From 9fae48bbd74f8f710bb5f72c2fa7f68e1f959c9f Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:35:36 +1200 Subject: [PATCH] FIX Allow clearing lazyloaded SearchableDropdownField. (#11324) --- src/Forms/SearchableDropdownTrait.php | 2 +- src/Forms/SearchableMultiDropdownField.php | 1 - tests/php/Forms/SearchableDropdownTraitTest.php | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Forms/SearchableDropdownTrait.php b/src/Forms/SearchableDropdownTrait.php index 97923f711..d8d164531 100644 --- a/src/Forms/SearchableDropdownTrait.php +++ b/src/Forms/SearchableDropdownTrait.php @@ -29,7 +29,7 @@ trait SearchableDropdownTrait 'search', ]; - private bool $isClearable = false; + private bool $isClearable = true; private bool $isLazyLoaded = false; diff --git a/src/Forms/SearchableMultiDropdownField.php b/src/Forms/SearchableMultiDropdownField.php index 3fe8f8c0a..90608a40d 100644 --- a/src/Forms/SearchableMultiDropdownField.php +++ b/src/Forms/SearchableMultiDropdownField.php @@ -24,6 +24,5 @@ class SearchableMultiDropdownField extends MultiSelectField $this->setLabelField($labelField); $this->addExtraClass('ss-searchable-dropdown-field'); $this->setIsMultiple(true); - $this->setIsClearable(true); } } diff --git a/tests/php/Forms/SearchableDropdownTraitTest.php b/tests/php/Forms/SearchableDropdownTraitTest.php index 7f4858c81..d3796cfa2 100644 --- a/tests/php/Forms/SearchableDropdownTraitTest.php +++ b/tests/php/Forms/SearchableDropdownTraitTest.php @@ -205,16 +205,16 @@ class SearchableDropdownTraitTest extends SapphireTest $field->setForm($form); $schema = $field->getSchemaDataDefaults(); $this->assertFalse($schema['lazyLoad']); - $this->assertFalse($schema['clearable']); + $this->assertTrue($schema['clearable']); $this->assertSame('Select or type to search...', $schema['placeholder']); $this->assertTrue($schema['searchable']); $field->setIsLazyLoaded(true); - $field->setIsClearable(true); + $field->setIsClearable(false); $field->setPlaceholder('My placeholder'); $field->setIsSearchable(false); $schema = $field->getSchemaDataDefaults(); $this->assertTrue($schema['lazyLoad']); - $this->assertTrue($schema['clearable']); + $this->assertFalse($schema['clearable']); $this->assertSame('My placeholder', $schema['placeholder']); $this->assertFalse($schema['searchable']); }