How to pass variable to javascript function through cq.ext.button handler?

不羁的心 提交于 2019-12-08 04:11:33

问题


I have the following code in my CQ dialog.xml

<toolbar
jcr:primaryType="cq:Widget"
xtype="toolbar">
<items
    jcr:primaryType="cq:WidgetCollection">
    <input
        jcr:primaryType="cq:Widget"
        xtype="textfield"
        name="./myInput">
    </input>
    <button
        jcr:primaryType="cq:Widget"
        xtype="button"
        name="./myButton"
        text="Submit" handler ="function() {passMyInput()};">
    </button>
</items>

I have implemented the function passMyInput() as follow:

passMyInput(){ alert("test");}

This works fine. My question is how to pass the value of ./myInput to the function passMyInput ?

I have tried handler ="function() passMyInput('./myInput')};" but it doesn't work


回答1:


The button's handler function receves 2 arguments, button b and eventObject e.

We can obtain the container dialog through the button and then use the getField() method to obtain the value of the field.

The modified hander function would be

function(b, e) {
    var dlg = b.findParentByType('dialog');
    var val = dlg.getField('./myInput').getValue();
    passMyInput(val);
}

For more info, refer widget docs



来源:https://stackoverflow.com/questions/24652112/how-to-pass-variable-to-javascript-function-through-cq-ext-button-handler

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