From 69988837d52b498dbc477f48fe4639de39e2d85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Mon, 3 Sep 2018 22:36:22 +0200 Subject: [PATCH] Fixed readonly on switch and checkbox field types (#3750) Credit to @gergo85 --- modules/backend/classes/FormField.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index dc7109c1d..0d3c629ac 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -248,6 +248,7 @@ class FormField * - radio - creates a set of radio buttons. * - checkbox - creates a single checkbox. * - checkboxlist - creates a checkbox list. + * - switch - creates a switch field. * @param string $type Specifies a render mode as described above * @param array $config A list of render mode specific config. */ @@ -255,6 +256,7 @@ class FormField { $this->type = strtolower($type) ?: $this->type; $this->config = $this->evalConfig($config); + return $this; } @@ -422,6 +424,7 @@ class FormField { $result = array_get($this->attributes, $position, []); $result = $this->filterAttributes($result, $position); + return $htmlBuild ? Html::attributes($result) : $result; } @@ -445,6 +448,10 @@ class FormField if ($position == 'field' && $this->readOnly) { $attributes = $attributes + ['readonly' => 'readonly']; + + if ($this->type == 'checkbox' || $this->type == 'switch') { + $attributes = $attributes + ['onclick' => 'return false;']; + } } return $attributes; @@ -507,9 +514,7 @@ class FormField 'data-trigger-closest-parent' => 'form' ]; - $attributes = $attributes + $newAttributes; - - return $attributes; + return $attributes + $newAttributes; } /** @@ -548,8 +553,7 @@ class FormField $newAttributes['data-input-preset-prefix-input'] = $prefixInput; } - $attributes = $attributes + $newAttributes; - return $attributes; + return $attributes + $newAttributes; } /**