This commit is contained in:
mcndave committed 2020-10-06 15:54:35 +00:00
commit 6020fa300d
8 files changed
+73 -42

No files matched your search

+4 -15
View File
@@ -38,26 +38,23 @@ class UiSelect extends UiElement implements Extension {
protected function setList(array $list, $selected, bool $strict = true) : void
{
foreach($list as $key => $item) {
$isSelected = $this->isSelected($key, $selected, $strict);
if ($item instanceof UiElement) {
$this->append($item);
continue;
}
elseif ( is_array($item) ) {
$obj = new UiElement("optgroup");
$obj->text($key);
$obj->attributes(['label' => $key]);
foreach($item as $subKey => $subItem) {
$obj->append($this->createOption((string) $subItem, $subKey, $isSelected));
$obj->append($this->createOption((string) $subItem, $subKey, $this->isSelected($subKey, $selected, $strict)));
}
}
else {
$obj = $this->createOption((string) $item, $key, $isSelected);
$obj = $this->createOption((string) $item, $key, $this->isSelected($key, $selected, $strict));
}
$this->append($obj);
}
}
@@ -77,14 +74,6 @@ class UiSelect extends UiElement implements Extension {
protected function isSelected($check, $value, bool $strict = true) : bool
{
if (false !== ( $f = filter_var($value, FILTER_VALIDATE_INT) ) ) {
$value = $f;
}
elseif (false !== ( $f = filter_var($value, FILTER_VALIDATE_FLOAT) ) ) {
$value = $f;
}
return $strict ? $check === $value : $check == $value;
}
}