PlayWithMagic / PlayWithMagic.org

PlayWithMagic.org is a web application that catalogs magic tricks and helps magicians build shows.
http://playwithmagic.github.io/PlayWithMagic.org/
Apache License 2.0
2 stars 1 forks source link

Figure out how to create Boolean Single Checkbox fields #95

Closed pkarjala closed 9 years ago

pkarjala commented 9 years ago

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.

pkarjala commented 9 years ago

Potential solution: http://stackoverflow.com/questions/8204708/how-do-i-bind-a-checkbox-to-a-boolean-in-play-framework

marknelsonengineer commented 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.

pkarjala commented 9 years ago

According to Prof. Johnson, we should be implementing this as the existing framework. Shelved for now.

pkarjala commented 9 years ago

Mark actually worked this out; we have a working implementation in one of the commits. Will have to have him dig it up.

marknelsonengineer commented 9 years ago

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.