如何显示尚未填充的字段

How to display which field has not been filled in

本文关键字:填充 字段 何显示 显示      更新时间:2023-09-26

我是AEM的新手。

我正在研究CQ5脚手架形式。其中有几个字段被标记为allowBlank=false,这可以防止作者更新表单,直到它们被处理。

问题是字段分散在一个很长的表单中,我们想告诉用户他们需要填写的字段的名称。

我不知道如何运行javascript当更新按钮被点击脚手架

在您的对话框中,添加一个侦听器来注册"beforesubmit"事件的回调,例如:

<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
          jcr:primaryType="cq:Dialog"
          title="Your Component"
          xtype="dialog">
    <items jcr:primaryType="cq:TabPanel">
...
    </items>
    <listeners
            jcr:primaryType="nt:unstructured"
            beforesubmit="function(dialog){return YourNamespace.validate(this);}" />
</jcr:root>

然后,在使用组件时包含的JavaScript文件中(例如通过向组件添加客户端库),您可以编写所需的JavaScript。例如:

YourNamespace = {};
YourNamespace.validate = function (dialog) {
    var buttonText = dialog.getField('./buttonText'),
        buttonUrl = dialog.getField('./buttonUrl'),
        isValid = true,
        validMsg = 'Validation Failed: You must fill out this field.';
    if(buttonText.getValue().length > 0 && buttonUrl.getValue().length === 0){
        isValid = false;
    }
    if(!isValid){
        CQ.Ext.Msg.show({title: 'Validation Failed', msg: validMsg, buttons: CQ.Ext.MessageBox.OK, icon: CQ.Ext.MessageBox.ERROR});
        return false;
    }
};

参考widgets API,详细了解如何处理作为参数传入的对象,例如上面示例中的"dialog"对象:https://docs.adobe.com/docs/en/cq/5-6-1/widgets-api/index.html