- Small bugfixes within value comparison for UiInput and small bugfixe in select repairing broken options.

This commit is contained in:
Dave Mc Nicoll 2020-05-20 15:32:41 -04:00
parent b4fc4dd37f
commit 69c7121981
4 changed files with 14 additions and 9 deletions

View File

@ -21,7 +21,7 @@ class UiInput extends UiElement implements Extension {
'tag-type' => "single", 'tag-type' => "single",
]; ];
protected ? string $value; protected /* ? mixed */ $value;
protected string $name; protected string $name;
@ -30,7 +30,7 @@ class UiInput extends UiElement implements Extension {
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>"; return "<?php echo ( new \\" . static::class . "() )->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; $this->name = $name;
@ -41,6 +41,11 @@ class UiInput extends UiElement implements Extension {
if ($options) { if ($options) {
$this->options += $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()); $this->attributes([ 'name' => $name ] + $attributes + $this->attributes + $this->objectAttribute());

View File

@ -12,8 +12,8 @@ class UiRadio extends UiInput {
]; ];
protected function objectAttribute() : array 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 [ return [
'checked' => "checked" 'checked' => "checked"
]; ];

View File

@ -38,24 +38,22 @@ class UiSelect extends UiElement implements Extension {
protected function setList(array $list, $selected, bool $strict = true) : void protected function setList(array $list, $selected, bool $strict = true) : void
{ {
foreach($list as $key => $item) { foreach($list as $key => $item) {
$isSelected = $this->isSelected($key, $selected, $strict);
if ($item instanceof UiElement) { if ($item instanceof UiElement) {
$this->append($item); $this->append($item);
continue; continue;
} }
elseif ( is_array($item) ) { elseif ( is_array($item) ) {
$obj = new UiElement("optgroup"); $obj = new UiElement("optgroup");
$obj->text($key); $obj->attributes(['label' => $key]);
foreach($item as $subKey => $subItem) { foreach($item as $subKey => $subItem) {
$obj->append($this->createOption($subItem, $subKey, $isSelected)); $obj->append($this->createOption($subItem, $subKey, $this->isSelected($subKey, $selected, $strict)));
} }
} }
else { else {
$obj = $this->createOption($item, $key, $isSelected); $obj = $this->createOption($item, $key, $this->isSelected($key, $selected, $strict));
} }
$this->append($obj); $this->append($obj);

View File

@ -28,6 +28,8 @@ class FormHandler {
$this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request); $this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request);
} }
$this->request->context = $this->context;
$this->formSent(); $this->formSent();
$this->initialize(); $this->initialize();
} }