tags:

views:

68

answers:

1

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.

A: 

It's probably the usual problem that unchecked checkboxes do not sent anything through on the request (they don't send 'off', they just don't send anything)

In your update action, try setting all the children to enabled=false before you apply the form params

tim_yates
I don't think thats the case here because checkbox on the parent working fine. I think its a bug, I am going to do a bit more testing and submit a report.
icon911