Reputation: 19682
The following constraint is unreliable because new Date()
will only be evaluated once, leaving you with a stale max date.
class Foo {
Date date
static constraints = {
date max: new Date()
}
}
So how do you reliably constrain a Date?
Upvotes: 0
Views: 167
Reputation: 12228
Assuming the date cannot be greater than the current date of validation:
static constraints = {
date(validator: { val, obj -> val <= new Date() })
}
Grails validator
Upvotes: 4