Overlay select-box options to change path field in Adobe cq5 dialog

In one of my dialogs, I have a field with xtype "pathfield". Depending on the value of this field, I want to change the "select-box" parameters (xtype = "selection", type = "select").

I used listeners and added a function for the "change" and "dialogclose" events for the "pathfield".

I can call the servlet and it sends a JSON response with parameters, however I cannot populate the select box with these parameters.

Below is the dialog.xml code

<select-product jcr:primaryType="cq:Widget"
                fieldDescription="Select Product (Product Details Page)"
                fieldLabel="Select Product" 
                height="{Long}40" key="productPath"
                name="./productPath" 
                style="height:21px" 
                width="{Long}350"
                rootPath="/content/MY_MSM_PATH" 
                xtype="pathfield">

    <listeners jcr:primaryType="nt:unstructured"
        change="function(){ var selectBox=$('select[name=features]');
        $.getJSON('/bin/featuresservlet?path=' + this.value, 
            function(jsonData){
                $.each(jsonData, function(i,data){
                    $('<option>').val(data.value).text(data.name).appendTo('select[name=features]');
                });
        }); }"

        dialogclose="function(){ 
            var selectBox=$('select[name=features]');
            $.getJSON('/bin/featuresservlet?path=' + this.value, function(jsonData){
                $.each(jsonData, function(i,data){
                    $('<option>').val(data.value).text(data.name).appendTo('select[name=features]');
                });
            }); }" />

</select-product> 

<features jcr:primaryType="cq:Widget" 
          fieldLabel="Select Features:"
          key="features" 
          name="./features" 
          type="select" 
          xtype="selection" />

      

+3


source to share


1 answer


you can use set options method to select xtype. Change your listener to something like this

dialogclose="function(pathfield){ 
        var dialog = pathfield.findParentByType('dialog');
        var selectBox = dialog.findByType('selection')[0]; //assuming this is the only selection you have
        $.getJSON('/bin/featuresservlet?path=' + this.value, function(jsonData){
            selectBox.setOptions(jsonData);
            selectBox.doLayout(flase,false);
        }); }" 

      

The data returned by your servlet should be in the following format:



[
 {
    "value": "valueOfOption1",
    "text": "textOfOption1"
 },
 {
    "value": "valueOfOption2",
    "text": "textOfOption2"
 }

]

      

Link: http://dev.day.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.form.Selection

+4


source







All Articles