Closed gigo6000 closed 1 year ago
This is expected behaviour with HTML checkboxes. If they aren't clicked then the data is not submitted to the server. This is not a Craft CMS/Commerce behaviour but the normal HTML checkbox behaviour.
You would need to have a hidden input with the same name before the normal checkbox submitting a false value if you want a false submitted.
{{ hiddenInput('fields[booleanField]', 0) }}
{{ input('checkbox', 'fields[booleanField]', 1, {checked: cart.booleanField}) }}
What happened?
Description
We have some custom fields of type
Lightswitch
and show them in the booking template as checkboxes:If any of those checkboxes is changed to checked and saved once then the next time you save the form and you uncheck them the cart/order values will still be
true/1
. The unchecked checkboxes are not sent in the request which is standard in html forms, but theactionUpdateCart()
is not updating this fields.Steps to reproduce
Lightswitch
Expected behavior
The value for the field should be
false/0
(cart.booleanField == 0
) after you uncheck the checkbox and save the form.Actual behavior
The value of the field is
true/1
(cart.booleanField == 1
) even after saving the form with the checkbox unchecked.Craft CMS version
4.4.15
Craft Commerce version
4.2.11
PHP version
8.1.16
Operating system and version
Debian
Database type and version
MariaDB 10.4.28
Image driver and version
No response
Installed plugins and versions