From 1c098f5f2da500623b562f2644ca3e40468f331e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 1 Oct 2025 09:04:58 +0200 Subject: [PATCH 1/5] TermInput: Override `getLabel()`, not the actual *label* We don't want a label for the term input, so let's ensure it doesn't get one with either decorator implementation. --- src/FormElement/TermInput.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/FormElement/TermInput.php b/src/FormElement/TermInput.php index c1c4b87db..51d7de451 100644 --- a/src/FormElement/TermInput.php +++ b/src/FormElement/TermInput.php @@ -190,6 +190,16 @@ public function getElements() return parent::getElements(); } + /** + * Will always return null as the label is passed to the main input + * + * @return null + */ + public function getLabel(): null + { + return null; + } + public function getValue($name = null, $default = null) { if ($name !== null) { @@ -460,13 +470,10 @@ public function getValueAttribute() }; $dataInput->setParent($this); - $label = $this->getLabel(); - $this->setLabel(null); - // TODO: Separator customization $mainInput = $this->createElement('text', 'value', [ 'id' => $searchInputId, - 'label' => $label, + 'label' => $this->label, 'required' => $this->isRequired(), 'placeholder' => $this->translate('Type to search. Separate multiple terms by comma.'), 'class' => 'term-input', From 5fc0838a6f506fd3d3f34e26f0cb665b123bfe16 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 1 Oct 2025 09:07:22 +0200 Subject: [PATCH 2/5] TermInput: Assemble upon preparing a multipart update Plus another small correction I accidentally noticed. --- src/FormElement/TermInput.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FormElement/TermInput.php b/src/FormElement/TermInput.php index 51d7de451..bc745e974 100644 --- a/src/FormElement/TermInput.php +++ b/src/FormElement/TermInput.php @@ -275,6 +275,8 @@ public function parseValue(string $value): array */ public function prepareMultipartUpdate(ServerRequestInterface $request): array { + $this->ensureAssembled(); + $updates = []; if ($this->valueHasBeenPasted()) { $updates[] = $this->termContainer(); @@ -294,7 +296,7 @@ public function prepareMultipartUpdate(ServerRequestInterface $request): array } if (empty($updates) && $this->hasBeenAutoSubmitted()) { - $updates[] = $updates[] = [ + $updates[] = [ HtmlString::create(json_encode( ['#' . Attribute::sanitizeId($this->getValueOfNameAttribute()) . '-search-input', 'bogus'] )), From e97ea6c42326ddff074daa08a84341412a1b46bd Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 1 Oct 2025 09:09:23 +0200 Subject: [PATCH 3/5] TermInput: Rename to `TermInputElement` Allows to load it using the form element loading of `CompatForm` --- src/FormElement/TermInput/TermContainer.php | 8 ++++---- src/FormElement/{TermInput.php => TermInputElement.php} | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) rename src/FormElement/{TermInput.php => TermInputElement.php} (98%) diff --git a/src/FormElement/TermInput/TermContainer.php b/src/FormElement/TermInput/TermContainer.php index 8eabf0e8c..2bb777d54 100644 --- a/src/FormElement/TermInput/TermContainer.php +++ b/src/FormElement/TermInput/TermContainer.php @@ -7,7 +7,7 @@ use ipl\Html\HtmlElement; use ipl\Html\Text; use ipl\I18n\Translation; -use ipl\Web\FormElement\TermInput; +use ipl\Web\FormElement\TermInputElement; use ipl\Web\Widget\Icon; class TermContainer extends BaseHtmlElement @@ -18,15 +18,15 @@ class TermContainer extends BaseHtmlElement protected $defaultAttributes = ['class' => 'terms']; - /** @var TermInput */ + /** @var TermInputElement */ protected $input; /** * Create a new TermContainer * - * @param TermInput $input + * @param TermInputElement $input */ - public function __construct(TermInput $input) + public function __construct(TermInputElement $input) { $this->input = $input; diff --git a/src/FormElement/TermInput.php b/src/FormElement/TermInputElement.php similarity index 98% rename from src/FormElement/TermInput.php rename to src/FormElement/TermInputElement.php index bc745e974..710071fd9 100644 --- a/src/FormElement/TermInput.php +++ b/src/FormElement/TermInputElement.php @@ -16,7 +16,7 @@ use ipl\Web\Url; use Psr\Http\Message\ServerRequestInterface; -class TermInput extends FieldsetElement +class TermInputElement extends FieldsetElement { use Events; @@ -445,10 +445,9 @@ protected function assemble() return ! $invalid; }] ]) extends HiddenElement { - /** @var TermInput */ - private $parent; + private ?TermInputElement $parent; - public function setParent(TermInput $parent): void + public function setParent(TermInputElement $parent): void { $this->parent = $parent; } From c330ed78bff8f5ae5a947f3667234ca460cec4ae Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 1 Oct 2025 09:27:58 +0200 Subject: [PATCH 4/5] Deprecate the old `TermInput` class --- src/FormElement/TermInput.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/FormElement/TermInput.php diff --git a/src/FormElement/TermInput.php b/src/FormElement/TermInput.php new file mode 100644 index 000000000..758777ce1 --- /dev/null +++ b/src/FormElement/TermInput.php @@ -0,0 +1,15 @@ + Date: Wed, 1 Oct 2025 10:43:36 +0200 Subject: [PATCH 5/5] TermInputElement: Add todo --- src/FormElement/TermInputElement.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/FormElement/TermInputElement.php b/src/FormElement/TermInputElement.php index 710071fd9..600450c94 100644 --- a/src/FormElement/TermInputElement.php +++ b/src/FormElement/TermInputElement.php @@ -333,6 +333,11 @@ private function valueHasBeenPasted(): bool public function onRegistered(Form $form) { + // TODO: In case the form is assembled "by hand", outside of "assemble()", this runs too early + // and no request is set yet. Additionally, this won't ever run in case the input is part + // of a fieldset as there is no "onRegistered()" call for fieldsets. There is clearly too + // much wrong here, so this needs to be properly fixed. + $termContainerId = Attribute::sanitizeId($this->getValueOfNameAttribute()) . '-terms'; $mainInputId = Attribute::sanitizeId($this->getValueOfNameAttribute()) . '-search-input'; $autoSubmittedBy = $form->getRequest()->getHeader('X-Icinga-Autosubmittedby');