Fixed readonly on switch and checkbox field types (#3750)

Credit to @gergo85
This commit is contained in:
Szabó Gergő 2018-09-03 22:36:22 +02:00 committed by Luke Towers
parent 55575e316b
commit 69988837d5
1 changed files with 9 additions and 5 deletions

View File

@ -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;
}
/**