From 39575ea55dcad5802319652478b7f420762ba07c Mon Sep 17 00:00:00 2001 From: iszmais Date: Thu, 26 Mar 2026 16:00:37 +0100 Subject: [PATCH] ignore null value on dynamic inputs --- .../Implementation/Component/Input/Field/File.php | 12 +++++++----- .../Component/Input/Field/HasDynamicInputs.php | 10 +++++----- .../tests/Component/Input/Field/TreeSelectTest.php | 9 ++++++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/components/ILIAS/UI/src/Implementation/Component/Input/Field/File.php b/components/ILIAS/UI/src/Implementation/Component/Input/Field/File.php index b35556cc1f05..da0170f084d3 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Input/Field/File.php +++ b/components/ILIAS/UI/src/Implementation/Component/Input/Field/File.php @@ -140,12 +140,14 @@ public function withValue($value): HasDynamicInputs $this->checkArg("value", $this->isClientSideValueOk($value), "Display value does not match input type."); $clone = clone $this; - foreach ($value as $data) { - $file_id = ($clone->hasMetadataInputs()) ? $data[0] : $data; + if (is_array($value)) { + foreach ($value as $data) { + $file_id = ($clone->hasMetadataInputs()) ? $data[0] : $data; - // that was not implicitly intended, but mapping dynamic inputs - // to the file-id is also a duplicate protection. - $clone->generated_dynamic_inputs[$file_id] = $clone->getTemplateForDynamicInputs()->withValue($data); + // that was not implicitly intended, but mapping dynamic inputs + // to the file-id is also a duplicate protection. + $clone->generated_dynamic_inputs[$file_id] = $clone->getTemplateForDynamicInputs()->withValue($data); + } } return $clone; diff --git a/components/ILIAS/UI/src/Implementation/Component/Input/Field/HasDynamicInputs.php b/components/ILIAS/UI/src/Implementation/Component/Input/Field/HasDynamicInputs.php index 94c2fbb2c769..f43b0437f350 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Input/Field/HasDynamicInputs.php +++ b/components/ILIAS/UI/src/Implementation/Component/Input/Field/HasDynamicInputs.php @@ -95,15 +95,15 @@ public function withValue($value): self $this->checkArg('value', $this->isClientSideValueOk($value), "Display value does not match input(-template) type."); $clone = clone $this; - if (!is_array($value)) { + if (is_array($value)) { + foreach ($value as $input_name => $input_value) { + $clone->generated_dynamic_inputs[$input_name] = $clone->getTemplateForDynamicInputs()->withValue($input_value); + } + } elseif ($value !== null) { $clone->generated_dynamic_inputs[] = $clone->getTemplateForDynamicInputs()->withValue($value); return $clone; } - foreach ($value as $input_name => $input_value) { - $clone->generated_dynamic_inputs[$input_name] = $clone->getTemplateForDynamicInputs()->withValue($input_value); - } - return $clone; } diff --git a/components/ILIAS/UI/tests/Component/Input/Field/TreeSelectTest.php b/components/ILIAS/UI/tests/Component/Input/Field/TreeSelectTest.php index 70da6eb1e99b..28c65caf8c4f 100644 --- a/components/ILIAS/UI/tests/Component/Input/Field/TreeSelectTest.php +++ b/components/ILIAS/UI/tests/Component/Input/Field/TreeSelectTest.php @@ -156,6 +156,14 @@ public function testWithValueForValidArguments(string|int|null $value): void $this->assertEquals([$value], $component->getValue()); } + public function testWithValueForEmptyValidArguments(): void + { + $node_retrieval = $this->getNodeRetrieval(); + $component = $this->getFieldFactory()->treeSelect($node_retrieval, ''); + $component = $component->withValue(null); + $this->assertEquals([], $component->getValue()); + } + public function testRenderWithValue(): void { $node_id = 'some-existing-node-id'; @@ -332,7 +340,6 @@ public static function getValidArgumentsForWithValue(): array ['1'], [''], [' '], - [null], ]; }