The entire logic for validation can be written in JS code as shown below which you can put in clientlibs and add the categories of clientlibs as cq.authoring.dialog
For Example:
I am doing the validation for a phone number field which accepts only 10 digit numbers in the dialog.
(function (document, $, ns) {
"use strict";
$(document).on("click", ".cq-dialog-submit", function (e) {
e.stopPropagation();
e.preventDefault();
var $form = $(this).closest("form.foundation-form"),
symbolid = $form.find("[name='./symbol']").val(),
message, clazz = "coral-Button ",
patterns = {
symboladd: /^([0-9]{10})\.?$/i
};
if(symbolid != "" && !patterns.symboladd.test(symbolid) && (symbolid != null)) {
ns.ui.helpers.prompt({
title: Granite.I18n.get("Invalid Number"),
message: "Please Enter a valid 10 Digit Phone Number",
actions: [{
id: "CANCEL",
text: "CANCEL",
className: "coral-Button"
}],
callback: function (actionId) {
if (actionId === "CANCEL") {
}
}
});
}else{
$form.submit();
}
});
})(document, Granite.$, Granite.author);
No comments:
Post a Comment
If you have any doubts or questions, please let us know.