Expand my Community achievements bar.

SOLVED

Request object - Sightly

Avatar

Community Advisor

Hi Guys,

 

Below is my use case:

Need to fill the form fields using the query parameters once the URL is hit. The form components are core components [not the AEM Forms]. Any working code [preferably in sightly] available on this?

 

Thanks,

Kiran Vedantam.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Vijayalakshmi_S 

 

Thanks for your response. But I have achived this using the global "request" object that is available in sightly like this: ${request.parameterMap.fieldName} and add this to the value attribute of the HTML.

 

Thanks,

Kiran Vedantam.

 

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @Kiran_Vedantam,

We can achieve this in JS. Please find below for the sample snippet.  Based on the pattern you get your queryParameters and form field name attribute, we can amend the logic accordingly. 

(() => {
    $(document).ready(() => {

       	var urlParams = new URLSearchParams(window.location.search);
        if(urlParams.has("firstName")){
            console.log("Has firstName as Query Param");
            $("input[name='firstName']").val(urlParams.get("firstName"));
        }
		if(urlParams.has("country")){
            // for select, value set should be <option> value for it to display the respective value as selected
			$("select[name='country']").val(urlParams.get("country")); 
		}

    }); 
}) ();

Vijayalakshmi_S_0-1636122770997.png

 

Avatar

Correct answer by
Community Advisor

Hi @Vijayalakshmi_S 

 

Thanks for your response. But I have achived this using the global "request" object that is available in sightly like this: ${request.parameterMap.fieldName} and add this to the value attribute of the HTML.

 

Thanks,

Kiran Vedantam.