October 13, 2020
Estimated Post Reading Time ~

TouchUI Dialog Listeners - AEM 6.3

In AEM 6.3, for using listeners you are searching for cq:listeners code but here are some event listeners which you can utilize on dialog validations:

For example: .cq-dialog-submit can be used to perform some operations before submitting the dialog in AEM 6.3 touchUI

listeners.js:

(function ($, $document) {
"use strict";
$document.on("dialog-ready", function() {
$(window).adaptTo("foundation-ui").alert("Open", "Dialog now open, event [dialog-ready]");
});

$(document).on("click", ".cq-dialog-submit", function (e) {
//$(window).adaptTo("foundation-ui").alert("Close", "Dialog closed, selector [.cq-dialog-submit]");
});

$document.on("dialog-ready", function() {
document.querySelector('form.cq-dialog').addEventListener('submit', function(){

//$(window).adaptTo("foundation-ui").alert("Close", "Dialog closed, selector [form.cq-dialog]");

}, true);
});

$document.on("dialog-success", function() {

//$(window).adaptTo("foundation-ui").alert("Save", "Dialog content saved, event [dialog-success]");

});

$document.on("dialog-closed", function() {
$(window).adaptTo("foundation-ui").alert("Close", "Dialog closed, event [dialog-closed]");
});
})($, $(document));

A simple scenario:
(function(document, $, ns) {
"use strict";
$(document).on("click", ".cq-dialog-submit", function(e) {

var $formminmax = $(this).closest("form.foundation-form");

var idSelector = $formminmax.find("[name='./idSelector']").val(); // This will contain the textfield data having name property as idSelector.

var field = $formminmax.find("[data-granite-coral-multifield-name='./prodId']");
var totalLinkCount = field.children('coral-multifield-item').length;
var prodData = []; //This will store the multifield data from the dialog.

for (var i = 0; i < totalLinkCount; i++) {
prodData.push(field.find($("[name='./productid']")[i]).val());
}
});

})(document, Granite.$, Granite.author);



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.