How to display which field has not been filled in

I'm new to AEM.

I'm working on a CQ5 scaffolding form. Several of the fields are marked with allowBlank=false which prevents the author from updating the form until they're dealt with.

The problem is that the fields are scattered through a very long form and we want to tell the user the name of the field they need to go fill in.

I can't figure out how to run javascript when the update button is clicked on the scaffold.



In your dialog, add a listener to register a callback for the "beforesubmit" event, such as the following:

<jcr:root xmlns:cq="" xmlns:jcr="" xmlns:nt=""
          title="Your Component"
    <items jcr:primaryType="cq:TabPanel">
            beforesubmit="function(dialog){return YourNamespace.validate(this);}" />


Then, in a JavaScript file that you include any time the component is used (such as by adding a client library to the component), you can write the JavaScript you require. For example:

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){{title: 'Validation Failed', msg: validMsg, buttons: CQ.Ext.MessageBox.OK, icon: CQ.Ext.MessageBox.ERROR});
        return false;

Reference the widgets API for details on what you can do with the objects you pass in as parameters, such as the "dialog" object in the example above:


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.