在cq对话框中,禁用复选框时禁用文本字段

sef*_*osu 2 checkbox dialog widget textfield aem

一个cq对话框问题,我的对话框中有两个小部件,文本字段和复选框.我需要的是,只有勾选复选框(true),然后文本字段才可供作者编辑,当勾选复选框时,必须禁用文本字段...

我已经搜索了一段时间,无法找到答案,请指教,这是我的两个小工具..

<checkbox
    jcr:primaryType="cq:Widget"
    defaultValue="{Boolean}false"
    fieldDescription="this is a checkbox"
    fieldLabel="enable something"
    name="./checkbox"
    type="checkbox"
    xtype="selection" />
<textfield
    jcr:primaryType="cq:Widget"
    fieldDescription= "this is a textfield"
    fieldLabel="textfield..."
    name="./textfield"
    enable={boolean}checkbox   // something gose here to make it enable or disable...
    xtype="textfield"/>
Run Code Online (Sandbox Code Playgroud)

rak*_*110 5

是的,您可以通过将侦听器附加到selectionchanged选中复选框时触发的事件来实现此目的.该API提供了将触发对微件公共事件的列表.

为了将侦听器附加到事件,您需要创建一个listeners在所需小部件下调用的类型为nt:unstructured的节点,并将事件名称作为属性添加到节点,其值将是您希望的处理函数执行.

在此输入图像描述

function(comp, val, isChecked) {
    var dlg = comp.findParentByType("dialog"); //find the dialog
    var textfield = dlg.getField("./textfield"); //get the field to disable

    /*hide or show component based on checked value */
    isChecked ? textfield.enable() : textfield.disable(); 
}
Run Code Online (Sandbox Code Playgroud)

面板内对话框的结构是

<checkbox
    jcr:primaryType="cq:Widget"
    defaultValue="{Boolean}false"
    fieldDescription="this is a checkbox"
    fieldLabel="enable something"
    name="./checkbox"
    type="checkbox"
    xtype="selection">
    <listeners jcr:primaryType="nt:unstructured" selectionchanged="function(comp, val, isChecked) {
        var dlg = comp.findParentByType("dialog");
        var textfield = dlg.getField("./textfield");
        isChecked ? textfield.enable() : textfield.disable(); 
    }"/>
</checkbox>
<textfield
    jcr:primaryType="cq:Widget"
    fieldDescription= "this is a textfield"
    fieldLabel="textfield..."
    name="./textfield"
    xtype="textfield"/>
Run Code Online (Sandbox Code Playgroud)