Cannot set g:checkbox to off for a child on one-to-many relationship

Posted by icon911 on Stack Overflow See other posts from Stack Overflow or by icon911
Published on 2010-04-22T00:29:49Z Indexed on 2010/04/22 0:33 UTC
Read the original article Hit count: 312

Filed under:
|

Got a weird issue with g:checkbox not being saved when its switched from on to off for a child in one-to-many relationship. For example:

class Parent {

 Boolean enabled

 static hasMany = [children: Child]

 static constraints = {
   enabled(blank: true, nullable: true)
 }


}

class Child {

 Boolean enabled

 static belongsTo = [parent: Parent]

 static constraints = {
   enabled(blank: true, nullable: true)
 }

}

Posting to Parent controller true/false values will work for Parent:

<g:checkBox name="enabled"  value="${parentInstance?.enabled}"/>

However, not for Child! When posting to Parent controller I can only go from false to true, trying to change from true to false again will not work:

<g:each in="${parentInstance.children}" status="i" var="child">
 <g:checkBox name="child[${i}].enabled" value="${child?.enabled}"  />
</g:each>

That seems to be a bug. Any ideas? Thanks.

© Stack Overflow or respective owner

Related posts about grails

Related posts about groovy