Description
Since Form::submit
is called with $clearMissing
set to false
in the case of a PATCH request, the submission of a form with an unchecked checkbox
field won't make its related data flip from true to false: the checkbox is simply considered not present (instead of present and unchecked) and not to be updated.
I've come up with the following workaround: since the front end does not rely on an HTTP form (obviously, thus the PATCH request) it is possible to systematically explicitly send a reserved value, like "__false"
, for any unchecked checkbox whose value must be updated; then in Symfony, the use of a data transformer bind this specific value to null
or false
, leaving all other values unchanged. I'm not satisfied with this patch since it requires to add transformers to all checkboxes fields in all forms, but it seems to work.
For the same reason, the issue also appears with an expanded + multiple choice
field type. However, since this field type just expects an array of checked checkboxes labels, there is no way of explicitely tell that all the other checkboxes are not checked, and the above workaround does not work anymore. Even if not exactly the same issue, it seems to be incidentally solved by the patch suggested in #17799 and implemented in #17771.
(All that on Symfony 2.6.4).