diff --git a/src/Form/UiInput.php b/src/Form/UiInput.php index fb8a63d..d3812ff 100644 --- a/src/Form/UiInput.php +++ b/src/Form/UiInput.php @@ -21,7 +21,7 @@ class UiInput extends UiElement implements Extension { 'tag-type' => "single", ]; - protected ? string $value; + protected /* ? mixed */ $value; protected string $name; @@ -30,7 +30,7 @@ class UiInput extends UiElement implements Extension { return "buildHtml($arguments) ?>"; } - public function buildHtml(string $name, ? string $value = null, array $attributes = [], array $options = []) : string + public function buildHtml(string $name, /*? mixed */ $value = null, array $attributes = [], array $options = []) : string { $this->name = $name; @@ -41,6 +41,11 @@ class UiInput extends UiElement implements Extension { if ($options) { $this->options += $options; } + + if ($attributes['class'] ?? false) { + $attributes['class'] .= " {$this->attributes['class']}"; + unset($this->attributes['class']); + } $this->attributes([ 'name' => $name ] + $attributes + $this->attributes + $this->objectAttribute()); diff --git a/src/Form/UiRadio.php b/src/Form/UiRadio.php index b51b523..d335d22 100644 --- a/src/Form/UiRadio.php +++ b/src/Form/UiRadio.php @@ -12,8 +12,8 @@ class UiRadio extends UiInput { ]; protected function objectAttribute() : array - { - if ( $this->options['value'] ?? false && ( $this->options['value'] === $this->value ) ) { + { + if ( ( $this->options['value'] ?? false ) && ( $this->options['value'] === $this->value ) ) { return [ 'checked' => "checked" ]; diff --git a/src/Form/UiSelect.php b/src/Form/UiSelect.php index 4d6bc31..2ad269b 100644 --- a/src/Form/UiSelect.php +++ b/src/Form/UiSelect.php @@ -38,24 +38,22 @@ 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($subItem, $subKey, $isSelected)); + $obj->append($this->createOption($subItem, $subKey, $this->isSelected($subKey, $selected, $strict))); } } else { - $obj = $this->createOption($item, $key, $isSelected); + $obj = $this->createOption($item, $key, $this->isSelected($key, $selected, $strict)); } $this->append($obj); diff --git a/src/Method/FormHandler.php b/src/Method/FormHandler.php index d49e145..4b7cd1c 100644 --- a/src/Method/FormHandler.php +++ b/src/Method/FormHandler.php @@ -28,6 +28,8 @@ class FormHandler { $this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request); } + $this->request->context = $this->context; + $this->formSent(); $this->initialize(); }