I have a component wherein, I have a container that has multifield which is representing rows in a table. We should be able to add 10 sets of rows, after which if we attempt to add another row, a custom error message must appear. Are there any OOO validations for this scenario? If not, are there any references to custom validations?
Solved! Go to Solution.
Views
Replies
Total Likes
#path-to-your-multifield means html element having multifield .
something like this : $(element).is("coral-select")
where coral-select is the element how multifield renders .
Hi @pixislinger ,
refer these for limiting the number of items in a multifield
https://sourcedcode.com/blog/aem/aem-granite-ui-multifield-maximum-items-validation#google_vignette
Hi @pixislinger
In Adobe Experience Manager (AEM), you can create a custom dialog validation for the number of multifield entries using JavaScript. Here's a step-by-step guide to implementing this validation:
Now, let's add the validation logic:
(function ($, $document) {
'use strict';
var maxRows = 10;
function validateMultifield() {
var multifieldPath = '#path-to-your-multifield';
var multifieldRows = $(multifieldPath + ' > .coral-Form-fieldset');
if (multifieldRows.length > maxRows) {
alert('Error: Maximum rows (' + maxRows + ') reached.');
return false;
}
return true;
}
$document.on('coral-dialog-open', function () {
$('.cq-dialog-submit').on('click', function (e) {
if (!validateMultifield()) {
e.preventDefault();
}
});
});
})($, $(document));
Replace '#path-to-your-multifield' with the actual path to your multifield.
Now, when you open the dialog and attempt to add more than 10 rows, an alert will appear displaying the custom error message, and the form submission will be prevented.
For more information on AEM dialogs and clientlibs, you can refer to the following resources:
These resources will help you understand how to work with AEM dialogs and clientlibs, and how to implement custom validations tailored to your specific use case.
Thank you
What does #path-to-your-multifield mean here? Could you give an example? Is it the one under cq:dialog?
#path-to-your-multifield means html element having multifield .
something like this : $(element).is("coral-select")
where coral-select is the element how multifield renders .
Views
Likes
Replies
Views
Likes
Replies