Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/backend/classes/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ class FormField
*/
public $preset;

/**
* @var bool Should the field's label for checkbox/switch fields be displayed above the field.
*/
public $showLabels;

/**
* Constructor.
* @param string $fieldName The name of the field
Expand Down Expand Up @@ -282,6 +287,7 @@ protected function evalConfig($config)
$applyConfigValues = [
'commentHtml',
'placeholder',
'showLabels',
'dependsOn',
'required',
'readOnly',
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/widgets/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ protected function getFieldDepends($field)
protected function showFieldLabels($field)
{
if (in_array($field->type, ['checkbox', 'switch', 'section'])) {
return false;
return $field->showLabels ?? false;
}

if ($field->type === 'widget') {
Expand Down
10 changes: 7 additions & 3 deletions modules/backend/widgets/form/partials/_field_checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
name="<?= $field->getName() ?>"
value="0"
<?= $this->previewMode ? 'disabled="disabled"' : '' ?>>

<input
type="checkbox"
id="<?= $field->getId() ?>"
Expand All @@ -14,10 +15,13 @@
<?= $field->isSelected() ? 'checked="checked"' : '' ?>
<?= $field->getAttributes() ?>>

<label for="<?= $field->getId() ?>">
<?= e(trans($field->label)) ?>
<label for="<?= $field->getId() ?>" class="<?= $field->showLabels ? 'show-labels' : '' ?>">
<?php if (!$field->showLabels): ?>
<?= e(trans($field->label)) ?>
<?php endif ?>
</label>
<?php if ($field->comment): ?>

<?php if (!$field->showLabels and $field->comment): ?>
<p class="help-block"><?= $field->commentHtml ? trans($field->comment) : e(trans($field->comment)) ?></p>
<?php endif ?>
</div>
6 changes: 4 additions & 2 deletions modules/backend/widgets/form/partials/_field_switch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<!-- Switch -->
<div class="<?= $previewMode ? 'disabled' : '' ?>">
<div class="field-switch">
<label for="<?= $field->getId() ?>"><?= e(trans($field->label)) ?></label>
<?php if ($field->comment): ?>
<?php if (!$field->showLabels): ?>
<label for="<?= $field->getId() ?>"><?= e(trans($field->label)) ?></label>
<?php endif ?>
<?php if (!$field->showLabels and $field->comment): ?>
<p class="help-block"><?= $field->commentHtml ? trans($field->comment) : e(trans($field->comment)) ?></p>
<?php endif ?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion modules/system/assets/ui/less/form.less
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

&.is-required {
> label:not(.custom-switch):after,
> .custom-checkbox > label:after,
> .custom-checkbox > label:not(.show-labels):after,
> .field-switch > label:after {
background-color: @color-form-required-asterisk;
width: 5px;
Expand Down
2 changes: 1 addition & 1 deletion modules/system/assets/ui/storm.css

Large diffs are not rendered by default.

Loading