From 0404ce536dacf64da6b604c8e54fcc2492ed718f Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Wed, 14 Oct 2015 11:17:24 -0400 Subject: [PATCH] Correctly adds #3179 --- src/definitions/modules/dropdown.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/definitions/modules/dropdown.js b/src/definitions/modules/dropdown.js index 5b5a11fe1..bc087e757 100644 --- a/src/definitions/modules/dropdown.js +++ b/src/definitions/modules/dropdown.js @@ -687,15 +687,14 @@ $.fn.dropdown = function(parameters) { searchTerm = (query !== undefined) ? query : module.get.query(), - $results = $(), + results = null, escapedTerm = module.escape.regExp(searchTerm), beginsWithRegExp = new RegExp('^' + escapedTerm, 'igm') ; // avoid loop if we're matching nothing - if( !module.has.query() ) { - $results = $item; - } - else { + if( module.has.query() ) { + results = []; + module.verbose('Searching for matching values', searchTerm); $item .each(function(){ @@ -707,11 +706,11 @@ $.fn.dropdown = function(parameters) { if(settings.match == 'both' || settings.match == 'text') { text = String(module.get.choiceText($choice, false)); if(text.search(beginsWithRegExp) !== -1) { - $results = $results.add($choice); + results.push(this); return true; } else if(settings.fullTextSearch && module.fuzzySearch(searchTerm, text)) { - $results = $results.add($choice); + results.push(this); return true; } } @@ -719,11 +718,11 @@ $.fn.dropdown = function(parameters) { value = String(module.get.choiceValue($choice, text)); if(value.search(beginsWithRegExp) !== -1) { - $results = $results.add($choice); + results.push(this); return true; } else if(settings.fullTextSearch && module.fuzzySearch(searchTerm, value)) { - $results = $results.add($choice); + results.push(this); return true; } } @@ -732,10 +731,12 @@ $.fn.dropdown = function(parameters) { } module.debug('Showing only matched items', searchTerm); module.remove.filteredItem(); - $item - .not($results) - .addClass(className.filtered) - ; + if(results){ + $item + .not(results) + .addClass(className.filtered) + ; + } }, fuzzySearch: function(query, term) {