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

Checkbox 在cq对话框中,未勾选复选框时禁用文本字段,checkbox,dialog,widget,textfield,aem,Checkbox,Dialog,Widget,Textfield,Aem,一个cq对话框问题,我的对话框中有两个小部件,textfield和checkbox。 我需要的是,只有当复选框被勾选(true)时,文本字段才可供作者编辑,当复选框未被勾选时,文本字段必须被禁用 我已经搜索了一段时间,找不到答案,请告知,这是我的两个小部件 <checkbox jcr:primaryType="cq:Widget" defaultValue="{Boolean}false" fieldDescription="this is a checkbox"

一个cq对话框问题,我的对话框中有两个小部件,textfield和checkbox。 我需要的是,只有当复选框被勾选(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"/>

是的,您可以通过将侦听器附加到选中复选框时触发的
selectionchanged
事件来实现这一点。提供将为小部件触发的公共事件列表

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

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(); 
}

面板中对话框的结构如下所示

<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"/>

如果textfield组件具有验证,该怎么办?如何也禁用此验证?