Add custom field validation in Content Fragment Model / Content Fragment | Community
Skip to main content
Level 4
February 1, 2021
Solved

Add custom field validation in Content Fragment Model / Content Fragment

  • February 1, 2021
  • 1 reply
  • 6355 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BrianKasingli

@mayukh007,

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-for-content-fragment-model-data-type/qaq-p/393540/comment-id/84746#M84746

}}

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.

1 reply

BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
February 2, 2021

@mayukh007,

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-for-content-fragment-model-data-type/qaq-p/393540/comment-id/84746#M84746

}}

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.

Mayukh007Author
Level 4
February 5, 2021
hI Brian, Thank you for the solution. What I understood from the solution is that I can add Regex to validate a field. It is not something content author can doo on the fly but Develop need to set the regex for them to use. In my case I have requirement where they will add 2 date fields and need to check if date1>date2...can we achieve this sort of validation...