Skip to content

[BUG]: The empty string is considered null when rendering checkboxes & radios #16648

@kuhler-Stratege

Description

@kuhler-Stratege

Describe the bug
In my project, I created a UI similar to the search page of PHPMyAdmin, where you can filter by different values of an sql table. This is done using several Radiogroups. When the user does not want to filter by a certain column, the value of the radio is an empty string. As default, all entries of an sql table are shown on that page, so per default the Radio with the empty string as value should be selected.
This is the bug: It does not. When I add an empty string as default and as checked attribute, the Radio is still not checked by default and I need to manually hack the checked flag into the html after rendering.

To Reproduce

Steps to reproduce the behavior:

$options = ['' => 'all', 1 => 'active'];
$html = '';
foreach ($options as $value => $label) {
            $radio = new Radio("IsActive");
            $radio->setLabel($label);
            $radio->setDefault($value);
            $attr['checked'] = '';
            $html .= $radio->render($attr);
}
echo $html;

Expected behavior
The rendering of the radio should flag the radio with the empty string as value to be checked if it matches the default or the selected value.

Details

  • Phalcon version: 5.8.0
  • PHP Version: 8.2.13
  • Operating System: Docker on MacOS
  • Installation type: Installing via pecl package manager
  • Server: Nginx

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

Type

No fields configured for Bug.

Projects

Status
Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions