1
votes

I have a custom multifield component with a maximum limit of 5 elements applied to the 'Add Item' button.

I need to add a similar listener logic to the 'OK' button of the dialog box to check if the minimum number of items (3) have been added or not.

How can that be achieved ? I didn't find any sample code to add a listener code to the button ..

1
From what I read, I understand that you managed to do it for one button but you aren't able to pull the same thing out for another button. Can you be more specific? Like including a snippet of code to illustrate your problem?rixo

1 Answers

1
votes

I've done this same sort of thing with a listener on the beforesubmit event of the Dialog (see beforesubmit for CQ.Dialog at http://dev.day.com/docs/en/cq/current/widgets-api/index.html - search for "Dialog"):

<listeners
  jcr:primaryType="nt:unstructured"
  beforesubmit="function(dialog){return myNamespace.myCustomFunction(dialog);}"/>

Then the custom JavaScript function, included on the page via a client library, could be something like this:

myNamespace = {};
myNamespace.myCustomFunction = function (dialog) {
    var isValid = function () {
        var valStatus = true;
        ... custom JavaScript/jQuery to check if 3 items exist ...
        return valStatus;
    };
    if (!isValid()) {
        CQ.Ext.Msg.show({title: 'Validation Error', msg: 'Must contain at least 3 items!', buttons: CQ.Ext.MessageBox.OK, icon: CQ.Ext.MessageBox.ERROR});
        return false;
    } else {
        return true;
    }
}