I have a user registration form where the fields are validated using command object. One of the fields is a checkbox, which must checked before proceeding the registration, and it isn't saved to the domain object. This checkbox has a corresponding Boolean field in the command object. When checkbox is not checked, a validation error is thrown from a custom validator.
The problem is, that this error is not propagated in the <g:renderErrors bean="${command}" as="xml"/>
block (the validator is fired correctly).
The command object:
class RegisterCommand {
...
Boolean termsChecked
...
static constraints = {
...
termsChecked validator: RegisterController.termsCheckedValidator
}
Validator:
static final termsCheckedValidator = {termsChecked, command, errors ->
if (!command.termsChecked) {
return 'registerCommand.termsChecked.required'
}
}
Checkbox in the GSP file:
<g:checkBox value="${command.termsChecked}" bean="${command}" name='termsChecked'/>
How this could be solved?