Hello,
We have a requirement where we need to add custom field validation when creating a content fragment (CF) using a custom content fragment model (CFM).
Currently when I create a CFM, I only see some limited option like can mark field as required or specify max char limit etc. But what if i need to create a custom date field called "Age" where I can specify Regex or logic that selected date can not be in past date etc, something like that...
I know we can create custom data types which I can use in my CFM but I dont see option to add validations on field link Regex, compare values, compare date value with current time etc.
We are in AEM 6.5.5.
Solved! Go to Solution.
Views
Replies
Total Likes
It is possible, I have provided a solution around over a week ago, please take a look here -> https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ootb-validation-options-fo...
}}
In short, you can use JavaScript to append the "pattern" attribute to a given HTML element, from there it will enable HTML validation for the content fragment field itself. Your client library should have a clientlib category of "dam.cfm.authoring.v2", so when you are on the cfm authoring view, your code will be run.
It is possible, I have provided a solution around over a week ago, please take a look here -> https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ootb-validation-options-fo...
}}
In short, you can use JavaScript to append the "pattern" attribute to a given HTML element, from there it will enable HTML validation for the content fragment field itself. Your client library should have a clientlib category of "dam.cfm.authoring.v2", so when you are on the cfm authoring view, your code will be run.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
The JS is working now in terms of showing red mark in field but I dont see Save button getting greyed out if I enter "not allowed" value. I can still save the CF.
Also can I use this "pattern" to compare 2 date fields , something link show red mark id Date1>Date2 in that CF...?
Views
Replies
Total Likes
Try this: regex to validate more than 1 capitalise letter.
$('input[name=carmodel]').first().attr('pattern', '[A-Z]+')
let $form = $('#aem-cfm-editor-elements-form');
let $saveBtn = $('.button-apply');
$('input').on('keyup', function() {
if ($form[0].checkValidity()) {
$saveBtn.removeClass('is-disabled');
} else {
$saveBtn.addClass('is-disabled');
}
});
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes