checkboxes form field having an option with value="0" and a default checked attribute:<field
name="test_checkboxes"
type="checkboxes"
label="Test Options"
checked="1"
>
<option value="0">Option Zero</option>
<option value="1">Option One</option>
</field>'0' as the value of the field (or select only option 0 and save the form).5.4
Option 0 should be checked, and Option 1 should be unchecked, respecting the saved value '0'.
Option 0 is unchecked, and Option 1 is checked (the default checked attribute is re-applied).
Joomla 5.4-dev / 6.0-dev, PHP 8.1+
In libraries/src/Form/Field/CheckboxesField.php line 153:
// True if the field has 'value' set. In other words, it has been stored, don't use the default values.
$hasValue = (isset($this->value) && !empty($this->value));In PHP, empty('0') and empty(0) return true. Because !empty($this->value) is used, when $this->value is '0' or 0, $hasValue evaluates to false.
When $hasValue is false:
$checkedOptions ignores the stored value '0' and falls back to $this->checkedOptions (the default checked attribute from XML).layouts/joomla/form/field/checkboxes.php line 73, (!$hasValue && $option->checked) also re-enables the default XML checked state.Checking $this->value !== null && $this->value !== '' && $this->value !== [] instead of !empty($this->value) properly recognizes '0' as a valid stored value.
| Labels |
Added:
No Code Attached Yet
|
||