From 7984747a3ff5d70b30c84f850efcc4d17a67a3b8 Mon Sep 17 00:00:00 2001 From: Ruud Seberechts Date: Fri, 18 Oct 2024 18:09:37 +0200 Subject: [PATCH 1/2] [Autocomplete] Only activate clear button plugin when there is a placeholder option --- src/Autocomplete/assets/dist/controller.js | 7 +++++-- src/Autocomplete/assets/src/controller.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Autocomplete/assets/dist/controller.js b/src/Autocomplete/assets/dist/controller.js index c6e9660b1d6..0efbe0d8e5e 100644 --- a/src/Autocomplete/assets/dist/controller.js +++ b/src/Autocomplete/assets/dist/controller.js @@ -15,7 +15,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -/* global Reflect, Promise, SuppressedError, Symbol */ +/* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __classPrivateFieldGet(receiver, state, kind, f) { @@ -227,7 +227,10 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def const plugins = {}; const isMultiple = !this.selectElement || this.selectElement.multiple; if (!this.formElement.disabled && !isMultiple) { - plugins.clear_button = { title: '' }; + const firstOption = this.selectElement.options[0]; + if (firstOption && firstOption.value === '') { + plugins.clear_button = { title: '' }; + } } if (isMultiple) { plugins.remove_button = { title: '' }; diff --git a/src/Autocomplete/assets/src/controller.ts b/src/Autocomplete/assets/src/controller.ts index af7f096a387..a526bab0130 100644 --- a/src/Autocomplete/assets/src/controller.ts +++ b/src/Autocomplete/assets/src/controller.ts @@ -127,10 +127,14 @@ export default class extends Controller { #getCommonConfig(): Partial { const plugins: TPluginHash = {}; - // multiple values excepted if this is NOT A select (i.e. input) or a multiple select + // Multiple values expected if this is NOT A select (i.e. input) or a multiple select const isMultiple = !this.selectElement || this.selectElement.multiple; if (!this.formElement.disabled && !isMultiple) { - plugins.clear_button = { title: '' }; + // Only activate clear button plugin when there is a placeholder option + const firstOption = this.selectElement.options[0]; + if (firstOption && firstOption.value === '') { + plugins.clear_button = { title: '' }; + } } if (isMultiple) { From b07700ddf6b7d45d6f4c4359c4fa29c804aed7ac Mon Sep 17 00:00:00 2001 From: Ruud Seberechts Date: Fri, 18 Oct 2024 18:21:18 +0200 Subject: [PATCH 2/2] [Autocomplete] Only activate clear button plugin when there is a placeholder option Placeholder is not necessarily the first option --- src/Autocomplete/assets/dist/controller.js | 5 +++-- src/Autocomplete/assets/src/controller.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Autocomplete/assets/dist/controller.js b/src/Autocomplete/assets/dist/controller.js index 0efbe0d8e5e..7533c4b27ae 100644 --- a/src/Autocomplete/assets/dist/controller.js +++ b/src/Autocomplete/assets/dist/controller.js @@ -227,8 +227,9 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def const plugins = {}; const isMultiple = !this.selectElement || this.selectElement.multiple; if (!this.formElement.disabled && !isMultiple) { - const firstOption = this.selectElement.options[0]; - if (firstOption && firstOption.value === '') { + const placeholderOptions = Array.from(this.selectElement.options) + .filter((option) => option.value === ''); + if (placeholderOptions.length) { plugins.clear_button = { title: '' }; } } diff --git a/src/Autocomplete/assets/src/controller.ts b/src/Autocomplete/assets/src/controller.ts index a526bab0130..ce5f933bb97 100644 --- a/src/Autocomplete/assets/src/controller.ts +++ b/src/Autocomplete/assets/src/controller.ts @@ -131,8 +131,9 @@ export default class extends Controller { const isMultiple = !this.selectElement || this.selectElement.multiple; if (!this.formElement.disabled && !isMultiple) { // Only activate clear button plugin when there is a placeholder option - const firstOption = this.selectElement.options[0]; - if (firstOption && firstOption.value === '') { + const placeholderOptions = Array.from(this.selectElement.options) + .filter((option) => option.value === ''); + if (placeholderOptions.length) { plugins.clear_button = { title: '' }; } }