- 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",
];
protected ? string $value;
protected /* ? mixed */ $value;
protected string $name;
@ -30,7 +30,7 @@ class UiInput extends UiElement implements Extension {
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;
@ -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());

View File

@ -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"
];

View File

@ -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);

View File

@ -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();
}