Closed pkarjala closed 9 years ago
I’m OK with the JavaScript approach as well.
Mark
On Apr 5, 2015, at 5:06 PM, Patrick A. Karjala notifications@github.com wrote:
Potential solution: http://stackoverflow.com/questions/8204708/how-do-i-bind-a-checkbox-to-a-boolean-in-play-framework http://stackoverflow.com/questions/8204708/how-do-i-bind-a-checkbox-to-a-boolean-in-play-framework — Reply to this email directly or view it on GitHub https://github.com/PlayWithMagic/PlayWithMagic/issues/95#issuecomment-89899199.
According to Prof. Johnson, we should be implementing this as the existing framework. Shelved for now.
Mark actually worked this out; we have a working implementation in one of the commits. Will have to have him dig it up.
Done. The framework binds checkboxes to Boolean variables. The Scala checkboxBoolean template holds checkboxes in two fields. The first is a checkbox field. The second is a hidden field (which must be after the checkbox field) with a value of false.. It ends up that when a field is checked, the 'checked' attribute gets bound to the Boolean/true. Unfortunately, if the field is unchecked, nothing gets bound. That's where the hidden field comes in. The parser skips over the checkbox field (it's unchecked) and finds the hidden field with a value of false. It binds the Boolean/false to the variable and you're done.
Currently the ShowEmail field uses a way-too-complex method for generating whether the single field is checked. Try to create a new template and way of doing this.
This is closely linked to the issue with form.value being "true | false" and Scala not recognizing this correctly.