allow to set (string) "true" as selectedValue for a checkbox, while default is (boolean) true and false for unselectedValue

also fix validation in case an old eTemplate with attribute (un)selected_value is used
This commit is contained in:
ralf 2024-08-07 09:21:37 +02:00
parent 75063e500a
commit d7391b4dc6
2 changed files with 6 additions and 5 deletions

View File

@ -61,9 +61,9 @@ export class Et2Checkbox extends Et2InputWidget(SlCheckbox)
} }
@property({type: String}) @property({type: String})
selectedValue = 'true'; selectedValue = true;
@property({type: String}) @property({type: String})
unselectedValue = ''; unselectedValue = false;
constructor() constructor()
{ {

View File

@ -68,12 +68,13 @@ class Checkbox extends Etemplate\Widget
// defaults for set and unset values // defaults for set and unset values
$selected_value = true; $selected_value = true;
$unselected_value = false; $unselected_value = false;
if(array_key_exists($value_attr, $this->attrs) || array_key_exists('unselectedValue', $this->attrs) || array_key_exists('unselected_value', $this->attrs)) if (array_key_exists($value_attr, $this->attrs) || array_key_exists('unselectedValue', $this->attrs) ||
array_key_exists('unselected_value', $this->attrs) || array_key_exists('selected_value', $this->attrs))
{ {
if(array_key_exists($value_attr, $this->attrs)) if (array_key_exists($value_attr, $this->attrs) || array_key_exists('selected_value', $this->attrs))
{ {
// Expand any content stuff // Expand any content stuff
$selected_value = self::expand_name($this->attrs[$value_attr], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); $selected_value = self::expand_name($this->attrs[$value_attr] ?? $this->attrs['selected_value'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
} }
if(array_key_exists('unselectedValue', $this->attrs) || array_key_exists('unselected_value', $this->attrs)) if(array_key_exists('unselectedValue', $this->attrs) || array_key_exists('unselected_value', $this->attrs))
{ {