Request object - Sightly | Community
Skip to main content
Kiran_Vedantam
Community Advisor
Community Advisor
November 4, 2021
Solved

Request object - Sightly

  • November 4, 2021
  • 2 replies
  • 1515 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kiran_Vedantam

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.

 

2 replies

Vijayalakshmi_S
Level 10
November 5, 2021

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")); 
		}

    }); 
}) ();

 

Kiran_Vedantam
Community Advisor
Kiran_VedantamCommunity AdvisorAuthorAccepted solution
Community Advisor
November 6, 2021

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.