No Code Attached Yet
avatar bhuvan-somisetty
bhuvan-somisetty
17 Sep 2026

What happened?

  1. Define a form XML with a 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>
  1. Bind or assign '0' as the value of the field (or select only option 0 and save the form).
  2. Render the form field.

Version

5.4

Expected result

Option 0 should be checked, and Option 1 should be unchecked, respecting the saved value '0'.

Actual result

Option 0 is unchecked, and Option 1 is checked (the default checked attribute is re-applied).

System Information

Joomla 5.4-dev / 6.0-dev, PHP 8.1+

Additional Comments

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:

  1. $checkedOptions ignores the stored value '0' and falls back to $this->checkedOptions (the default checked attribute from XML).
  2. In 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.

avatar bhuvan-somisetty bhuvan-somisetty - open - 17 Sep 2026
avatar joomla-cms-bot joomla-cms-bot - change - 17 Sep 2026
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 17 Sep 2026

Add a Comment

Login with GitHub to post a comment