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

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

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.
Ravi_Pampana
Ravi_PampanaAccepted solution
New Participant
Apr 11, 2022 5:58 AM UTC

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

3 replies

Ravi_Pampana
New Participant
Apr 11, 2022 5:24 AM UTC

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/

 

 

Translate
Level 4
Apr 11, 2022 5:44 AM UTC

do I have to write this code inside 

 $(document).on("dialog-ready", function (){});
this function or outside it.
Translate
Ravi_Pampana
Ravi_PampanaAccepted solution
New Participant
Apr 11, 2022 5:58 AM UTC

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

Translate