7 Replies Latest reply on Oct 15, 2015 7:30 PM by vkeerthy

    Populate dropdown field using java script

    vkeerthy Level 1

      I have an address field in AEM forms which is positioned in a panel as attached in the screenshot Field inside panel.png

      I can add 3 address instances to the form.

      My use case is to display the captured address (3) in a dropdown list in subsequent screen. For this I have a JS method which is being called in calculate expression for the dropdownlist filed (as per Dropdownlist configuration.png).

      The code is as below. But for some reason, this method return object is not recognised as array Object. Can some shed light on this. Please see the attached output of the form (Form-output.png)

      function addressSetter() { console.log("Logger from JS file"); var address1 = window.guideBridge.resolveNode("guide[0].guide1[0].guideRootPanel[0].panel14440455204641444045520610[0].addressCollections[0].panel1[0].address[0]"); var address2 = window.guideBridge.resolveNode("guide[0].guide1[0].guideRootPanel[0].panel14440455204641444045520610[0].addressCollections[0].panel1[1].address[0]"); var address3 = window.guideBridge.resolveNode("guide[0].guide1[0].guideRootPanel[0].panel14440455204641444045520610[0].addressCollections[0].panel1[2].address[0]"); /*items = [];*/ var items = []; if (address1.value){ console.log("The value for address 1 is ::"+address1.value); items.push("1="+address1.value); }   if (address2.value){ console.log("The value for address 2 is ::"+address2.value); items.push("2="+address2.value); } if (address3.value){ console.log("The value for address 2 is ::"+address3.value); items.push("3="+address3.value); } return items; }
      • 0. Re: Populate dropdown field using java script
        vkeerthy Level 1

        Thanks Rishi for the reply and sorry for not being precise on my questions.

        I am able to construct the array and it is able to hold the values. However my struggle is how to invoke this method from options expression. The document [1] is talking about individual values though. When I try to call a method (which has values as return) inside in options expression field, it simply doesn't populate. 

        In my options expression, I tried below and it didn't work

        optionsPainter (The method that returns values)

         

         

        Kindly advise on where I am making mistake.

         

         

         

         

        [1] https://helpx.adobe.com/aem-forms/6/adaptive-form-expressions.html#main-pars_header_7