gpt4 book ai didi

aem - 如何使用监听器使文本字段成为必需

转载 作者:行者123 更新时间:2023-12-02 09:36:01 27 4
gpt4 key购买 nike

我在选择器上有监听器,可以根据所选值隐藏和显示文本字段。我想实现将显示的值应该强制填写。我在监听器中使用 alloweddBlank 为 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>

监听器 JavaScript:

MyDialog.setRequired = function(field,value) {
var dialog = field.findParentByType("dialog"),
email = dialog.getField('./email1');

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

关于aem - 如何使用监听器使文本字段成为必需,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26192217/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com