Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lanceybg opened this issue Sep 23, 2023 · 0 comments

Comments

@lanceybg
Copy link

lanceybg commented Sep 23, 2023

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 ); ?>
...
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant