Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return Custom Validator Error Grails

I'm only getting the default validator message. What am I doing wrong?

class Questao {


static hasMany = [alternativas:Alternativa]

static constraints = {

    alternativas (validator: {val, obj ->
       if(val.size() < 2)
            return ['validator.message'] //custom message
        })
}
}

/i18n

questao.alternativas.validator.message = "must be greater than two"

default.invalid.validator.message= Property [{0}] of class [{1}] with value [{2}] does not pass custom validation

Thanks

like image 476
Luccas Avatar asked Dec 28 '22 05:12

Luccas


1 Answers

You're returning a list containing your message code - you need to return just the code:

alternativas validator: { val, obj ->
   if (val.size() < 2) {
      return 'validator.message' //custom message
   }
}
like image 85
Burt Beckwith Avatar answered Jan 05 '23 11:01

Burt Beckwith