CQ5 - Populating options dynamically when xtype is selected

I've been banging my head about this for hours. I am trying to populate parameters dynamically as xtype and cannot get it to work. Here is my dialog.xml

<resourceType
            jcr:primaryType="cq:Panel"
            title="Header Type">
            <items jcr:primaryType="cq:WidgetCollection">
                <headerType
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Header Type"
                        name="./headerType"
                        type="select"
                        xtype="selection">
                    <options jcr:primaryType="cq:WidgetCollection">
                        <categories
                            jcr:primaryType="cq:Widget"
                            path="/content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json"
                            width="500"
                            xtype="cqinclude" />
                    </options>
                </headerType>
            </items>
        </resourceType>

      

Json I am creating for:

content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json

      

It looks something like this:

{"jcr:primaryType":"nt:unstructured","item_1":  
{"jcr:primaryType":"nt:unstructured","text":"small","parameter":"small"},"item_2":
{"jcr:primaryType":"nt:unstructured","text":"medium","parameter":"medium"},"item_3":
{"jcr:primaryType":"nt:unstructured","text":"large","parameter":"large"},"item_4":
{"jcr:primaryType":"nt:unstructured","text":"none","parameter":"none"}} 

      

When I go to open the dialog nothing happens, I just get JS TypeError: snippet.xtype is undefined

Any help is appreciated!

+3


source to share


1 answer


Parameters for selection

xtype can be set dynamically in two ways.

  • by setting the options property to a path returning an array of JSON options
  • Writing a function that sets options (using the setOptions method) and passing that function as a value to optionsProvider .

In both cases, the data returned in JSON must be an array.



To use method 1, in the headerType node, set the property options

to a path that will provide the JSON data. Set optionsRoot

proprety to the name of the property containing the JSON array. Set optionsTextField

the property name in the JSON data to be text. Set the optionsValueField

name of the property in the JSOn data to be a value.

Detailed guidance on this can be found here: http://jenikya.com/blog/2013/04/dynamic-dialog-data-in-cq5.html

For method 2 refer to this

+7


source







All Articles