Skip to content

Commit

Permalink
Merge pull request #342 from driehle/4.x
Browse files Browse the repository at this point in the history
Fix label position for radio boxes in 4.x series
  • Loading branch information
neilime authored Apr 5, 2022
2 parents 36a5b17 + c6d311e commit 8de90b3
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 50 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- 4.x
pull_request:
paths-ignore:
- "**.md"
Expand Down
7 changes: 4 additions & 3 deletions src/TwbsHelper/Form/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public function render(\Laminas\Form\ElementInterface $element, ?string $labelPo
switch (true) {
// Form group disabled
case $element->getOption('form_group') === false:
// Radio elements
case $elementType === 'radio':
// All "button" elements in inline form
case in_array($elementType, ['submit', 'button', 'reset'], true)
&& $layout === \TwbsHelper\Form\View\Helper\Form::LAYOUT_INLINE:
Expand Down Expand Up @@ -305,9 +303,12 @@ protected function getDefaultLabelPosition(\Laminas\Form\ElementInterface $eleme
}
}

if ($element instanceof \Laminas\Form\Element\MultiCheckbox) {
return self::LABEL_PREPEND;
}

switch ($element->getAttribute('type')) {
case 'checkbox':
case 'radio':
return self::LABEL_APPEND;
case 'file':
if ($element->getOption('custom')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'name' => 'customRadio',
'type' => 'radio',
'options' => [
'form_group' => false,
'custom' => true,
'value_options' => [
[
Expand Down Expand Up @@ -68,6 +69,7 @@
'type' => 'radio',
'options' => [
'layout' => \TwbsHelper\Form\View\Helper\Form::LAYOUT_INLINE,
'form_group' => false,
'custom' => true,
'value_options' => [
[
Expand Down Expand Up @@ -110,6 +112,7 @@
'name' => 'radioDisabled',
'type' => 'radio',
'options' => [
'form_group' => false,
'custom' => true,
'value_options' => [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
'type' => 'radio',
'name' => 'gridRadios',
'options' => [
'column' => 'sm-10',
'value_options' => [
[
'label' => 'First radio',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Radios</legend>
<div class="col-sm-10">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1">
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2">
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
<div class="form-group">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1">
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2">
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Radios</legend>
<div class="col-sm-10">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1">
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2">
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
<div class="form-group">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1">
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2">
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
</div>
</div>
</div>
</div>
Expand Down
53 changes: 29 additions & 24 deletions website/docs/usage/components/forms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1092,17 +1092,19 @@ echo $this->form(
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Radios</legend>
<div class="col-sm-10">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1"></input>
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2"></input>
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled="disabled"></input>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
<div class="form-group">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1"></input>
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2"></input>
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled="disabled"></input>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -1189,7 +1191,6 @@ echo $this->form(
'type' => 'radio',
'name' => 'gridRadios',
'options' => [
'column' => 'sm-10',
'value_options' => [
[
'label' => 'First radio',
Expand Down Expand Up @@ -2010,17 +2011,19 @@ echo $this->form(
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Radios</legend>
<div class="col-sm-10">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1"></input>
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2"></input>
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled="disabled"></input>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
<div class="form-group">
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios1" value="option1"></input>
<label class="form-check-label" for="gridRadios1">First radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios2" value="option2"></input>
<label class="form-check-label" for="gridRadios2">Second radio</label>
</div>
<div class="form-check">
<input type="radio" name="fieldset[gridRadios]" class="form-check-input" id="gridRadios3" value="option3" disabled="disabled"></input>
<label class="form-check-label" for="gridRadios3">Third disabled radio</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -2107,7 +2110,6 @@ echo $this->form(
'type' => 'radio',
'name' => 'gridRadios',
'options' => [
'column' => 'sm-10',
'value_options' => [
[
'label' => 'First radio',
Expand Down Expand Up @@ -3137,6 +3139,7 @@ echo $this->formRow(
'name' => 'customRadio',
'type' => 'radio',
'options' => [
'form_group' => false,
'custom' => true,
'value_options' => [
[
Expand Down Expand Up @@ -3191,6 +3194,7 @@ echo $this->formRow(
'type' => 'radio',
'options' => [
'layout' => \TwbsHelper\Form\View\Helper\Form::LAYOUT_INLINE,
'form_group' => false,
'custom' => true,
'value_options' => [
[
Expand Down Expand Up @@ -3263,6 +3267,7 @@ echo $this->formRow(
'name' => 'radioDisabled',
'type' => 'radio',
'options' => [
'form_group' => false,
'custom' => true,
'value_options' => [
[
Expand Down

0 comments on commit 8de90b3

Please sign in to comment.