Skip to content

Commit d05ca33

Browse files
committed
Fix checkbox group
Clicking a label in a checkboxes group selects the intended value.
1 parent c36740c commit d05ca33

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/BootstrapForm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public function checkboxElement(
512512

513513
$options['class'] = trim($options['class'] . ' ' . $this->getFieldErrorClass($name));
514514

515-
$label = ($label !== null ? $this->form->label($name, $label, $labelOptions) : '');
515+
$label = ($label !== null ? $this->form->label(isset($options['id']) ? $options['id'] : $name, $label, $labelOptions) : '');
516516
$inputElement = $this->form->checkbox($name, $value, $checked, $options);
517517
$labelElement = $inputElement . $label . $this->getFieldError($name);
518518

@@ -541,11 +541,12 @@ public function checkboxes(
541541
array $options = []
542542
) {
543543
$elements = '';
544+
$index = 0;
544545

545546
foreach ($choices as $value => $choiceLabel) {
546547
$checked = in_array($value, (array)$checkedValues);
547548

548-
$elements .= $this->checkboxElement($name, $choiceLabel, $value, $checked, $inline, $options);
549+
$elements .= $this->checkboxElement($name, $choiceLabel, $value, $checked, $inline, $options + ['id' => $name . ++$index]);
549550
}
550551

551552
$comment = $this->getComment($options);

0 commit comments

Comments
 (0)