apache / apache/grails-core

g:checkbox no way to bind g:checkbox unchecked which String value

Open
#11,339 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

An empty passed "_${field}" which tells the binding to set an empty or false value, but this only works for boolean values. If the value is a String or a List, empty behavior is not correctly performed.

A very simple example where we want to map checkboxes to String values:
```
class Person {

String name
List languages
String comments
boolean engineer

static constraints = {
name()
languages nullable: true
comments nullable: true
engineer nullable: true
}
}
```
Using the following form:
```




Name



Languages
English  
Spanish  
French


Comments
Likes Cats


Engineer







```
The checkbox behavior binds correctly for boolean, String, and List values, BUT when a String value is unchecked, it does not bind the null state, and when a List values are unchecked, it works as expected until you uncheck the last value. It does not correctly bind the empty state.

The rendered form is here:

```



Name



Languages
English  
Spanish  
French


Comments
Likes Cats


Engineer





```

Notice it is correctly sending the following fields to the controller to notify the controller it wants to overwrite its values

```

```

but the only one honored by the controller is the one that maps to a boolean value

``

A Simple example
```
grails create-app
grails
create-domain-class Person
generate-all Person
# modify Person.groovy, create.gsp and edit.gsp
run-app
```

This example can be checked out here:

https://github.com/codeconsole/formbinding

Contributor guide

Open the contributing guide

Research direction

Start with the linked formbinding example and reproduce the behavior using g:checkbox for String and List properties. Trace how the generated _languages and _comments fields are handled by the controller and form binding, comparing them with the boolean case. Done means unchecked String and last unchecked List values bind to the empty state as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.