Reputation: 1
I have this:
class Usuario {
String username
String password
String passwordDos
String nombre
String apellidoPaterno
String apellidoMaterno
Date fechaDeNacimiento
String sexo
String correo
static constraints = {
username blank: false, unique: true, validator: { val, obj ->
obj.password != val
return ['usuario.userPassError']
}
password blank: false, validator: { val, obj ->
obj.passwordDos == val
return ['usuario.passDiferentes']
}
passwordDos blank: false
nombre blank: false, maxSize: 64
apellidoPaterno blank: false, maxSize: 64
apellidoMaterno blank: true, maxSize: 64
sexo inList: ["Femenino", "Masculino"]
correo blank: false, maxSize: 128, email:true
}
}
I want to return in the error message, but I'm not doing wrong, I could explain alguein please?
Upvotes: 0
Views: 395
Reputation: 120286
I'd expect there to be some sort of conditional return in the validator closures. As it stands, it looks like they'll always fail, returning the error code.
Try writing your custom validators like:
// username validator
validator: { val, obj ->
obj.password == val ? 'userPassError' : true
}
// password validator
validator: { val, obj ->
obj.passwordDos != val ? 'passDiferentes' : true
}
Note the different message codes that are being returned, too.
Then, make sure you have the following in your appropriate grails-app/i18n/messages*
file(s):
usuario.username.userPassError = Username and password cannot be the same
usuario.password.passDiferentes = Password does not match password confirmation
Upvotes: 2