Skip to content

Commit

Permalink
Bootstrap 4: $inline* and $grid* class variables are set only in the …
Browse files Browse the repository at this point in the history
…corresponding mode
  • Loading branch information
xificurk committed May 2, 2020
1 parent 8f14a72 commit 14e46a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/FormRenderer/Bootstrap4Renderer.php
Expand Up @@ -82,10 +82,10 @@ function (Nette\Forms\IControl $control): ?string {
);
$template->useCustomControls = $this->useCustomControls;
$template->mode = $this->mode;
$template->gridOffsetClass = sprintf('offset-sm-%d', $this->labelCols);
$template->gridLabelClass = sprintf('col-sm-%d', $this->labelCols);
$template->gridControlClass = sprintf('col-sm-%d', $this->controlCols);
$template->inlineSpacingClasses = 'mb-2 mr-2';
$template->gridOffsetClass = $this->mode === self::MODE_HORIZONTAL ? sprintf('offset-sm-%d', $this->labelCols) : null;
$template->gridLabelClass = $this->mode === self::MODE_HORIZONTAL ? sprintf('col-sm-%d col-form-label', $this->labelCols) : null;
$template->gridControlClass = $this->mode === self::MODE_HORIZONTAL ? sprintf('col-sm-%d', $this->controlCols) : null;
$template->inlineSpacingClasses = $this->mode === self::MODE_INLINE ? 'mb-2 mr-2' : null;

return $templateRenderer->render($form);
}
Expand Down
11 changes: 5 additions & 6 deletions src/FormRenderer/templates/bootstrap4.latte
Expand Up @@ -85,10 +85,9 @@
{define #label}
<label n:if="$control->getLabel()" n:name="$control" n:class="
$control->getLabelPrototype()->class,
$mode === horizontal ? $gridLabelClass,
$mode === horizontal ? col-form-label,
$gridLabelClass,
$mode === horizontal && in_array($control->getOption('type'), [radio, checkboxlist]) ? pt-sm-0,
$mode === inline ? $inlineSpacingClasses
$inlineSpacingClasses
" />
{/define}

Expand Down Expand Up @@ -127,7 +126,7 @@
<small n:if="$control->getOption('description') !== null" n:class="
form-text,
text-muted,
$mode === inline ? $inlineSpacingClasses
$inlineSpacingClasses
">{$control->getOption('description')|safeTranslate}</small>
{/define}

Expand Down Expand Up @@ -218,7 +217,7 @@
<div n:foreach="$control->items as $k => $v" n:class="
$control->getSeparatorPrototype()->class,
$useCustomControls ? 'custom-control custom-checkbox' : form-check,
$mode === inline ? $inlineSpacingClasses,
$inlineSpacingClasses,
$mode !== inline && !$control->separatorPrototype->getName() ? ($useCustomControls ? custom-control-inline : form-check-inline)
">
<input n:name="$control:$k" n:class="
Expand All @@ -237,7 +236,7 @@
<div n:foreach="$control->items as $k => $v" n:class="
$control->getSeparatorPrototype()->class,
$useCustomControls ? 'custom-control custom-radio' : form-check,
$mode === inline ? $inlineSpacingClasses,
$inlineSpacingClasses,
$mode !== inline && !$control->separatorPrototype->getName() ? ($useCustomControls ? custom-control-inline : form-check-inline)
">
<input n:name="$control:$k" n:class="
Expand Down

0 comments on commit 14e46a0

Please sign in to comment.