Skip to content

ActiveField - RadioButtonGroup with checked item on load - issue with BS 5.x #141

Open
@lanceybg

Description

@lanceybg

When rendering RadioButtonGroup with model that already has one of the valid options selected, ActiveField.php renders the label with 'active' CSS class added, which does not seem to be needed with BootStrap 5.x.

The result is that, whatever other option you select, the initially selected one still stays visually selected.

The fix is simple (attached .diff), but I'm not sure it does not break any other behaviour (so far haven't found any issues).
fix-activeform.diff.txt

--- ActiveField.php	2023-09-23 23:00:37.981027706 +0300
+++ ActiveField.php	2023-09-23 22:59:31.389222800 +0300
@@ -1833,7 +1833,7 @@
                     $wrapperOptions = ['class' => [$type.$css]];
                 }
                 if ($asBtnGrp) {
-                    if ($checked) {
+                    if (($checked) and (!$isBs5)) {
                         Html::addCssClass($labelOpts, 'active');
                     }
                     $opts['autocomplete'] = 'off';

Sample code which shows the issue:

<?php
...
$types = array(1 => 'Type A', 2 => 'Type B');
$form->type = 1;
...
<?= $form->field($form, 'type')->radioButtonGroup( $types ); ?>
...
?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions