Expand my Community achievements bar.

SOLVED

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

Avatar

Level 5

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Community Advisor

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/

 

 

Avatar

Level 5

do I have to write this code inside 

 $(document).on("dialog-ready", function (){});
this function or outside it.

Avatar

Correct answer by
Community Advisor

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