I would like to build a customized validator in my Command object, to make sure the field email address of a form will not be empty if the notifyMe checkbox is selected.
Here is my latest attempt to implement it:
email(blank: true, nullable: true, email: true,
validator: {email, creditProviderCommand ->
if (creditProviderCommand.notifyMe == 'on')
return email.size() > 0})
I have tried also with email != null and email != '' but it is not working in both cases, meaning that the form submission is accepted even with the notifyMe checkbox checked and the email address field left blank.
The code of the action handles the validation error properly (even unique constraint). Any idea of what I am doing wrong ?
Thank you very much for your help.
notifyMe,booleanorString? What value is actually assigned to it? I supposebooleanorBoolean, so you just need to check it for truth, not for'on'. - Victor Sergienko