user1134181
user1134181

Reputation:

GORM constraints: validator for boolean fields

I'm trying to set a simple restriction on the field of the domain object using the closure in constraints but it does not work.

For example, I have three fields:

boolean organization1 = false
boolean organization2 = false
boolean organization3 = false

organization3 field can be set only if organization1 field is set:

class Organization {
    boolean organization1 = false
    boolean organization2 = false
    boolean organization3 = false

    static constraints = {
        organization1()
        organization2()
        organization3(validator:{organization3, organization -> return organization.organization1 ? true : false })
    }
}

Controller actions and GSP- views I get by using scaffolding. That's what happens:

enter image description here enter image description here

How to properly set a restriction? I would be very grateful for the information. Thanks to all.

Upvotes: 0

Views: 555

Answers (1)

injecteer
injecteer

Reputation: 20707

Not sure if I got it correctly, but I'd put the validator this way:

static constraints = {
    organization3 validator:{ org3, org -> !org3 || org3 && org.organization1 } 
}

Upvotes: 1

Related Questions