Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Request object - Sightly

Kiran_Vedantam
Community Advisor
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
Kiran_Vedantam
Correct answer by
Community Advisor
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
Vijayalakshmi_S
Community Advisor
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

 

Kiran_Vedantam
Correct answer by
Community Advisor
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