From ab54d0c620a8ff72506da937d1951fbd52cb7a97 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Wed, 28 Jan 2026 16:21:47 +0100 Subject: [PATCH] fix(ui/40605): use additional load code to intercept button id for file input label --- .../Component/Input/Field/Renderer.php | 19 +++++++++++-------- .../Component/Input/Field/FileInputTest.php | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/components/ILIAS/UI/src/Implementation/Component/Input/Field/Renderer.php b/components/ILIAS/UI/src/Implementation/Component/Input/Field/Renderer.php index 7c731d09bfd6..eac4002c29f2 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Input/Field/Renderer.php +++ b/components/ILIAS/UI/src/Implementation/Component/Input/Field/Renderer.php @@ -909,19 +909,22 @@ protected function renderFileField(F\File $input, RendererInterface $default_ren $input = $this->initClientsideFileInput($input); // display the action button (to choose files). - $template->setVariable('ACTION_BUTTON', $default_renderer->render( - $this->getUIFactory()->button()->shy( - $input->getMaxFiles() <= 1 - ? $this->txt('select_file_from_computer') - : $this->txt('select_files_from_computer'), - '#' - ) - )); + $button_id = null; + $button = $this->getUIFactory()->button()->shy( + $input->getMaxFiles() <= 1 + ? $this->txt('select_file_from_computer') + : $this->txt('select_files_from_computer'), + '#' + )->withAdditionalOnLoadCode(static function (string $id) use (&$button_id) { + $button_id = $id; + }); + $template->setVariable('ACTION_BUTTON', $default_renderer->render($button)); return $this->wrapInFormContext( $input, $input->getLabel(), $template->get(), + $button_id ); } diff --git a/components/ILIAS/UI/tests/Component/Input/Field/FileInputTest.php b/components/ILIAS/UI/tests/Component/Input/Field/FileInputTest.php index 4d8a24a2b145..688ef6493129 100755 --- a/components/ILIAS/UI/tests/Component/Input/Field/FileInputTest.php +++ b/components/ILIAS/UI/tests/Component/Input/Field/FileInputTest.php @@ -176,7 +176,7 @@ class="ui-input-file-input-error-msg" data-dz-error-msg> ', $byline, - null, + 'id_2', 'id_3' ); $this->assertEquals($expected, $this->render($file_input)); @@ -260,7 +260,7 @@ class="ui-input-file-input-error-msg" data-dz-error-msg> ', null, - null, + 'id_3', 'id_4' ); $this->assertEquals($expected, $this->render($file_input)); @@ -346,7 +346,7 @@ class="c-field-text" /> ', null, - null, + 'id_5', 'id_6', ); $this->assertEquals($expected, $this->render($file_input)); @@ -441,7 +441,7 @@ class="c-field-text" /> ', null, - null, + 'id_5', 'id_6' ); $this->assertEquals($expected, $this->render($file_input));