From b5203fdc50d87e9993f9bf77143dd9b541e8d659 Mon Sep 17 00:00:00 2001 From: Andrew Paxley Date: Tue, 8 Oct 2024 17:04:07 +1300 Subject: [PATCH] FIX remove placeholder search text on readonly field --- src/Forms/SearchableDropdownTrait.php | 4 +++- tests/php/Forms/SearchableDropdownTraitTest.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Forms/SearchableDropdownTrait.php b/src/Forms/SearchableDropdownTrait.php index 83a9a0bc1..53cb48856 100644 --- a/src/Forms/SearchableDropdownTrait.php +++ b/src/Forms/SearchableDropdownTrait.php @@ -139,7 +139,6 @@ trait SearchableDropdownTrait return $emptyString; } } - $name = $this->getName(); if ($this->getUseDynamicPlaceholder()) { if ($this->getIsSearchable()) { if (!$this->getIsLazyLoaded()) { @@ -598,6 +597,9 @@ trait SearchableDropdownTrait $field->setSource($this->sourceList); $field->setReadonly(true); + // Remove the text "Type to search..." on a read-only field + $field->setPlaceholder(''); + return $field; } } diff --git a/tests/php/Forms/SearchableDropdownTraitTest.php b/tests/php/Forms/SearchableDropdownTraitTest.php index d3796cfa2..45c021726 100644 --- a/tests/php/Forms/SearchableDropdownTraitTest.php +++ b/tests/php/Forms/SearchableDropdownTraitTest.php @@ -73,6 +73,8 @@ class SearchableDropdownTraitTest extends SapphireTest $this->assertSame('My empty string', $field->getPlaceholder()); $field->setPlaceholder('My placeholder'); $this->assertSame('My placeholder', $field->getPlaceholder()); + $readonlyField = $field->performReadonlyTransformation(); + $this->assertSame('', $readonlyField->getPlaceholder()); } public function testSeachContext(): void