How can I show error message on the the fields in AEM? | Community
Skip to main content
Level 4
April 11, 2022
Solved

How can I show error message on the the fields in AEM?

  • April 11, 2022
  • 1 reply
  • 2068 views

hi, how can I show the messages as the warning or errors in AEM fields for eg:

if I have two text fields then I have to put a condition in which the two fields cannot have the same name or values into it.

if that happens then It should show which the red marking or line around the text field as an error or warning .I want to ask how can I do that and where to put conditions for it.

thank you

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 Ravi_Pampana

You can add the js file with category

"[granite.ui.coral.foundation]"

 

Or create your own category and add it cq:dialog using extraClientlibs as provided in below link

https://aemhints.com/2020/11/02/validating-dialog-value/

 

No need to add it dialog-ready

1 reply

Ravi_Pampana
Community Advisor
Community Advisor
April 11, 2022

Hi,

 

You can add granite:class property to those 2 fields and using below script you can retrieve the values from fields and compare the value and show the error message if both are same

 

$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {

  selector: ".secondfield",

  validate: function(el) {

   var firstVal = $(".firstfield").val();

    var secondVal = $(".secondfield").val();

    //Compare the values and show error message 

  }

});

 

Check below post for detailed explanation

https://aemhints.com/2020/11/02/validating-dialog-value/

 

 

Level 4
April 11, 2022

do I have to write this code inside 

 $(document).on("dialog-ready", function (){});
this function or outside it.
Ravi_Pampana
Community Advisor
Ravi_PampanaCommunity AdvisorAccepted solution
Community Advisor
April 11, 2022

You can add the js file with category

"[granite.ui.coral.foundation]"

 

Or create your own category and add it cq:dialog using extraClientlibs as provided in below link

https://aemhints.com/2020/11/02/validating-dialog-value/

 

No need to add it dialog-ready