injecteer
injecteer

Reputation: 20707

Custom validation fails

In my Grails 3.1.11 app I have a domain class

class Ability {

  String valueTypeName

  static constraints = {
    valueTypeName validator:{ val, obj, errors ->
      println val
      errors.rejectValue 'valueTypeName', 'err'
      return 'default.invalid.validator.message'
    }
  }
}

and scaffolded controller & views:

class AbilityController {
  static scaffold = Ability
}

Upon saving / updating, I can see println output in the console, but the object is never rejected... I tried returning false, but it remains the same. Rejecting the value explicitely helps only by inserting.

What am I missing?

Upvotes: 0

Views: 41

Answers (1)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27255

This is a bug in the scaffolding. See https://github.com/grails3-plugins/scaffolding/issues/24

Note that validation is not failing. The validation works. The update really isn't sent to the database. The problem is that the scaffolding shows a view that suggests that the update was made, but it wasn't.

Upvotes: 1

Related Questions