From caafe5c5f18ab0726d91e77df4a15848306f4452 Mon Sep 17 00:00:00 2001 From: John Osterman Date: Wed, 31 Oct 2018 16:13:31 -0400 Subject: [PATCH] Adds noResults property to prevent onChange event from fireing when keyword search results in "no results" --- src/selectr.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/selectr.js b/src/selectr.js index e060065..282bc2a 100644 --- a/src/selectr.js +++ b/src/selectr.js @@ -709,7 +709,7 @@ if (e.which === 13) { - if (this.config.taggable && this.input.value.length > 0) { + if ( this.noResults || (this.config.taggable && this.input.value.length > 0) ) { return false; } @@ -1952,12 +1952,14 @@ // Append results if ( !f.childElementCount ) { if ( !this.config.taggable ) { + this.noResults = true; this.setMessage( "no results." ); } } else { // Highlight top result (@binary-koan #26) var prevEl = this.items[this.navIndex]; var firstEl = f.querySelector(".selectr-option:not(.excluded)"); + this.noResults = false; util.removeClass( prevEl, "active" ); this.navIndex = firstEl.idx;