How to change background color of validation message depending on condition.

0
This birthday date is eligible for vote. So I want to change this message background color to green. and If it not eligible then color should be red. Does anyone know how to do this. Thanks is advance.
asked
2 answers
0

You can use dynamic classes for that. In the validation message go to “appearance” → Dynamic classes.

 

Add: (if $currentObjcet/dateofbirth = (condition for it to be eligible) then ‘valid_dob’ else ‘’)

Then add a custom class “valid_dob” in your project theme folder in either a seperate scss file or into the “custom-variables.scss”

 

valid_dob class:

.valid_dob {

background-color: green !important;

}

 

Maybe you need to adjust the text color or some other things aswell but you can just add those in this class.

 

Hope this works!

answered
0

Your message box is not a validation message. It is rather an information-message based on the value of attribute dob (date of birth). Difference is that a validation message will also prevent the user from saving data and moving on. In this case you probably want the user stopped is dob results in an age below 18 saying ‘You are not eligible to vote’ with red background. So add a text-field on your page, below the dob-input mimicking the validation message, visibility: only visible if person is eligible;

To that textbox, add a class and in customs.scss add the class and the background-color. No need for “!important”. The specific class will be enough and if it is not enough, then make your selector more specific by adding  more parent-classes.

Btw. ‘eligible for vote’: do you mean ‘allowed to vote’ or ‘eligible to get voted’?

answered