How to open first item of multifield on load of dialog?

穿精又带淫゛_ 提交于 2020-01-23 03:14:25

问题


I need to open first item of multifield on dialog load. I looked at the API documentation of multifield but not able to find.

<promo
                    jcr:primaryType="cq:Widget"
                    fieldLabel="abcd"
                    hideLabel="false"
                    itemId="abcd"
                    name="./abcd"
                    xtype="[multifield]">
                    <fieldConfig
                        jcr:primaryType="cq:Widget"
                        hideLabel="false"
                        layout="form"
                        name="./abcd"
                        title="abcd Item Info"
                        xtype="customPanel">
                        <items jcr:primaryType="cq:WidgetCollection">

                        </items>
                    </fieldConfig>
                </promo>

Please suggest.


回答1:


You can listen to the loadcontent event fired by the Multifield after the content has been loaded. If there was no content available initially, use the addItem() method to add an item and then redo the layout.

A sample configuration using multiple path field is shown below. You can adapt the same as per your requirements.

<promo
    jcr:primaryType="cq:Widget"
    fieldLabel="Select Paths"
    name="./paths"
    xtype="multifield">
    <fieldConfig
        jcr:primaryType="nt:unstructured"
        xtype="pathfield" />
    <listeners
        jcr:primaryType="nt:unstructured"
        loadcontent="function(field, record)
        {
           if(record.get('paths') == undefined)
          {
            field.addItem(); field.doLayout();
          }
        }" />
</promo>



回答2:


Improving the above provided solution, try to replace the loadcontent line with,

loadcontent="function(field, record) {if(field.getValue().length == 0) {field.addItem();} }"


来源:https://stackoverflow.com/questions/32073857/how-to-open-first-item-of-multifield-on-load-of-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!