This project is read-only.

Orchard.Forms Checkbox only works correctly when Checked defaults to false


I ran across an issue when trying to use a checkbox in a projection layout form. If I set the Checked option to true, the checkbox always displays as checked on the form even though the behavior from it being unchecked worked as expected. What I found is that when the checkbox value is being serialized to the database, if it's unchecked, no value is stored in the XML. Upon loading, since the value is null, the default value in the form definition is used, so it displays checked.

The expected behavior works because the value that comes back in the State is null which is not equal to the checked value "on". Of course, when it is checked, the State value is "on", so that works as well.

I'm not sure what the fix for this is, just yet. I ended up working around it by inverting the logic (the checkbox label is "Hide ..." instead of "Show ...")


agriffard wrote Jul 25, 2014 at 11:09 AM

Bertrand fixed a bug recently on 1.x for projection field that haven't a value defined.
May be it would need a similar fix.