diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 2b03704..465458f 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -1116,7 +1116,7 @@ class Choices { _handleBackspace(activeItems) { if (this.config.removeItems && activeItems) { const lastItem = activeItems[activeItems.length - 1]; - const hasHighlightedItems = activeItems.some((item) => item.highlighted === true); + const hasHighlightedItems = activeItems.some(item => item.highlighted); // If editing the last item is allowed and there are not other selected items, // we can edit the item value. Otherwise if we can remove items, remove all selected items @@ -1167,10 +1167,15 @@ class Choices { } } - // If no duplicates are allowed, and the value already exists // in the array - const isUnique = !activeItems.some((item) => item.value === isType('String', value) ? value.trim() : value); + const isUnique = !activeItems.some((item) => { + if (isType('String', value)) { + return item.value === value.trim(); + } + + return item.value === value; + }); if ( !isUnique && @@ -1179,7 +1184,9 @@ class Choices { canAddItem ) { canAddItem = false; - notice = isType('Function', this.config.uniqueItemText) ? this.config.uniqueItemText(value) : this.config.uniqueItemText; + notice = isType('Function', this.config.uniqueItemText) ? + this.config.uniqueItemText(value) : + this.config.uniqueItemText; } return { @@ -1294,7 +1301,7 @@ class Choices { } const choices = this.store.getChoices(); - const hasUnactiveChoices = choices.some((option) => option.active !== true); + const hasUnactiveChoices = choices.some(option => !option.active); // Run callback if it is a function if (this.input === document.activeElement) { @@ -1726,7 +1733,7 @@ class Choices { this.hideDropdown(true); } } else { - const hasHighlightedItems = activeItems.some((item) => item.highlighted === true); + const hasHighlightedItems = activeItems.some(item => item.highlighted); // De-select any highlighted items if (hasHighlightedItems) { @@ -1824,7 +1831,7 @@ class Choices { if (this.containerOuter.contains(target)) { const activeItems = this.store.getItemsFilteredByActive(); const hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState); - const hasHighlightedItems = activeItems.some((item) => item.highlighted === true); + const hasHighlightedItems = activeItems.some(item => item.highlighted); const blurActions = { text: () => { if (target === this.input) { @@ -2187,9 +2194,16 @@ class Choices { return strToEl(`