Skip to content

Commit 7a0cce4

Browse files
fhelferthibsy
authored andcommitted
[FIX] #47057 UI: ensure one selected Field\Select option. (ILIAS-eLearning#11009)
* Fixes https://mantis.ilias.de/view.php?id=47057 * Update empty value check
1 parent 7032b0e commit 7a0cce4

File tree

1 file changed

+5
-4
lines changed
  • components/ILIAS/UI/src/Implementation/Component/Input/Field

1 file changed

+5
-4
lines changed

components/ILIAS/UI/src/Implementation/Component/Input/Field/Renderer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,25 +488,26 @@ public function renderSelectField(F\Select $component, RendererInterface $defaul
488488
$this->applyName($component, $tpl);
489489

490490
$value = $component->getValue();
491+
$value_is_empty = $value === null || $value === '';
491492
//disable first option if required.
492493
$tpl->setCurrentBlock("options");
493-
if (!$value) {
494+
if ($value_is_empty) {
494495
$tpl->setVariable("SELECTED", 'selected="selected"');
495496
}
496-
if ($component->isRequired() && !$value) {
497+
if ($value_is_empty && $component->isRequired()) {
497498
$tpl->setVariable("DISABLED_OPTION", "disabled");
498499
$tpl->setVariable("HIDDEN", "hidden");
499500
}
500501

501-
if (!($value && $component->isRequired())) {
502+
if ($value_is_empty || !$component->isRequired()) {
502503
$tpl->setVariable("VALUE", null);
503504
$tpl->setVariable("VALUE_STR", $component->isRequired() ? $this->txt('ui_select_dropdown_label') : '-');
504505
$tpl->parseCurrentBlock();
505506
}
506507

507508
foreach ($component->getOptions() as $option_key => $option_value) {
508509
$tpl->setCurrentBlock("options");
509-
if ($value == $option_key) {
510+
if (!$value_is_empty && $value == $option_key) {
510511
$tpl->setVariable("SELECTED", 'selected="selected"');
511512
}
512513
$tpl->setVariable("VALUE", $option_key);

0 commit comments

Comments
 (0)