Forums

Handle Arrays on checkboxes doesn't remove last one

farmington 23 Sep, 2015
I'm seeing an odd behavior in the handling of checkboxes, and I'm not sure if it's new or has always been there. (I developed my site about 6 months ago, and could have sworn I had tested this fully then).

I have a set of checkboxes that the user clicks to indicate their choices. I have your custom code to explode the checkboxes on load, and use HandleArrays to implode on submit. It generally works OK, but has the following behavior:

If you have several selected, and unclick some, but leave at least one checked, it saves the smaller set of selections correctly.
If you deselect all the boxes and save, it doesn't save an empty field to the database. It leaves whatever was in the field previously. It should remove that data if no items are currently selected.

If I manually go into the database and empty the field, it correctly displays all the boxes as unchecked and doesn't change it upon save.
GreyHead 24 Sep, 2015
Answer
Hi farmington,

Checkbox groups behave a little differently to other input elements. If nothing is selected then 'nothing' is submitted - there is not even an empty entry. So ChronoForms sees nothing and the DB Save doesn't include that value leaving the previous one unchanged.

The fix for this is to enable the Ghost setting (at the bottom of the Checkbox Group settings) to submit an empty value if nothing else is selected.

Bob
farmington 24 Sep, 2015
That fixed it. Thanks!
(I'm embarrassed that I missed that in the first round of testing!)
This topic is locked and no more replies can be posted.