From 23f0b7cb9d65004263aa3c065dc9fa8b6931ade5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daiana=20Cambruzzi=20=C3=81vila?= Date: Wed, 15 Apr 2020 08:36:33 -0300 Subject: [PATCH] Fix Issue 630: allow triggering of 'search' event when clearing the input field --- src/scripts/choices.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts index 62e8f83..a25add9 100644 --- a/src/scripts/choices.ts +++ b/src/scripts/choices.ts @@ -1230,7 +1230,7 @@ class Choices implements Choices { } _handleSearch(value: string): void { - if (!value || !this.input.isFocussed) { + if (!this.input.isFocussed) { return; } @@ -1239,7 +1239,11 @@ class Choices implements Choices { const hasUnactiveChoices = choices.some((option) => !option.active); // Check that we have a value to search and the input was an alphanumeric character - if (value && value.length >= searchFloor) { + if ( + value !== null && + typeof value !== 'undefined' && + value.length >= searchFloor + ) { const resultCount = searchChoices ? this._searchChoices(value) : 0; // Trigger search event this.passedElement.triggerEvent(EVENTS.search, {