Aem 如何使用侦听器使textfield成为必需的

Aem 如何使用侦听器使textfield成为必需的,aem,Aem,我让listener over selector根据所选值隐藏和显示textfield。我想实现将显示的值必须填写。我在我的听众中使用allowdBlank为true,但它不起作用。下面是我的听众 function(selection,record,path) { var dialog=selection.findParentByType('panel'); var email = dialog.getComponent('email1'); var url = dialog.getCompon

我让listener over selector根据所选值隐藏和显示textfield。我想实现将显示的值必须填写。我在我的听众中使用allowdBlank为true,但它不起作用。下面是我的听众

function(selection,record,path)
{
var dialog=selection.findParentByType('panel');
var email = dialog.getComponent('email1');
var url = dialog.getComponent('url1');
if(record == 'email'){
    url.hide();
    url.setValue("");
    email.show(); //how to make email manadory  
}
if(record == 'link'){
    email.hide();
    email.setValue("");
    url.show(); 
}
}
谢谢

我在selectionChanged监听器上使用了“allowBlank”。我已经多次成功地使用它按需/不按需切换字段。下面是一些适用于您的示例的工作代码(我省略了与必填字段无关的部分)。它使用的是
getField
方法,而不是getComponent:

对话框:

<type
    jcr:primaryType="cq:Widget"
    fieldLabel="Type"
    name="./type"
    type="radio"
    xtype="selection">
    <options jcr:primaryType="cq:WidgetCollection">
        <email
                jcr:primaryType="nt:unstructured"
                text="Email"
                value="email"/>
        <url
                jcr:primaryType="nt:unstructured"
                text="Url"
                value="url"/>
    </options>
    <listeners
        jcr:primaryType="nt:unstructured"
        selectionchanged="function(field,value) { 
                              MyDialog.setRequired(field,value); }"/>
</type>
MyDialog.setRequired = function(field,value) {
    var dialog = field.findParentByType("dialog"),
        email = dialog.getField('./email1');

    if('url' == value) {
        email.allowBlank = true;
    }else{
        email.allowBlank = false;
    }
};

我也试过了,如果我没记错的话,在创建组件之后就不可能更改强制标志了。