Skip to content

Commit 9751853

Browse files
committed
Fix checkbox / radio label
1 parent 0f2acd9 commit 9751853

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/BootstrapForm.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ public function checkboxElement(
499499
array $options = []
500500
) {
501501
$wrapperClass = $inline ? 'form-check form-check-inline' : 'form-check';
502-
$labelOptions = ['class' => 'form-check-label'];
503502
$label = $this->getLabelTitle($label, $name, $options) ?: '';
503+
$labelOptions = ['class' => 'form-check-label'];
504504

505505
if ( ! isset($options['class'])) {
506506
$options['class'] = 'form-check-input';
@@ -511,8 +511,8 @@ public function checkboxElement(
511511
}
512512

513513
$options['class'] = trim($options['class'] . ' ' . $this->getFieldErrorClass($name));
514-
$label = ($label !== null ? '<label ' . $this->html->attributes($labelOptions) . '>' . $label . '</label>' : '');
515514

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

@@ -609,8 +609,8 @@ public function radioElement(
609609
) {
610610
$wrapperClass = $inline ? 'form-check form-check-inline' : 'form-check';
611611
$label = $this->getLabelTitle($label, $name, $options) ?: '';
612+
$labelOptions = ['class' => 'form-check-label'];
612613
$displayError = ! Arr::exists($options, 'no-error');
613-
614614
$options = Arr::except($options, 'no-error');
615615

616616
$options['class'] = 'form-check-input' . (isset($options['class']) ? (' ' . $options['class']) : '');
@@ -620,9 +620,8 @@ public function radioElement(
620620
}
621621

622622
$options['class'] = $options['class'] . ($displayError ? (' ' . $this->getFieldErrorClass($name)) : '');
623-
$labelOptions = ['class' => 'form-check-label', 'for' => $this->form->getIdAttribute($name, $options)];
624-
$label = ($label !== null ? '<label ' . $this->html->attributes($labelOptions) . '>' . $label . '</label>' : '');
625623

624+
$label = ($label !== null ? $this->form->label(Arr::get($options, 'id') ?: $name, $label, $labelOptions) : '');
626625
$inputElement = $this->form->radio($name, $value, $checked, $options);
627626
$labelElement = $inputElement . $label . ($displayError ? $this->getFieldError($name) : '');
628627

@@ -653,13 +652,14 @@ public function radios(
653652
$elements = '';
654653
$label = $this->getLabelTitle($label, $name, $options);
655654
$radioOptions = array_merge(['no-error' => true], $options);
655+
$index = 0;
656656

657657
Arr::forget($radioOptions, 'required');
658658

659659
foreach ($choices as $value => $choiceLabel) {
660660
$checked = $value === $checkedValue;
661661

662-
$elements .= $this->radioElement($name, $choiceLabel, $value, $checked, $inline, $radioOptions);
662+
$elements .= $this->radioElement($name, $choiceLabel, $value, $checked, $inline, $radioOptions + ['id' => $name . ++$index]);
663663
}
664664

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

0 commit comments

Comments
 (0)