diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index 1f63e72ec8..62502ca42c 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -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 @@ -282,6 +287,7 @@ protected function evalConfig($config) $applyConfigValues = [ 'commentHtml', 'placeholder', + 'showLabels', 'dependsOn', 'required', 'readOnly', diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 5598810d93..2a361a58d7 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -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') { diff --git a/modules/backend/widgets/form/partials/_field_checkbox.php b/modules/backend/widgets/form/partials/_field_checkbox.php index 8303506510..4a12de3fa2 100644 --- a/modules/backend/widgets/form/partials/_field_checkbox.php +++ b/modules/backend/widgets/form/partials/_field_checkbox.php @@ -5,6 +5,7 @@ name="getName() ?>" value="0" previewMode ? 'disabled="disabled"' : '' ?>> + isSelected() ? 'checked="checked"' : '' ?> getAttributes() ?>> -