From f1539ad181c15678302f45d2f45274a37391abaa Mon Sep 17 00:00:00 2001 From: Joe Ibershoff Date: Wed, 29 Apr 2015 20:26:56 -0400 Subject: [PATCH 1/2] feat(typeahead): handles min-length of 0 --- src/typeahead/test/typeahead.spec.js | 9 +++++++++ src/typeahead/typeahead.js | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 741621e65c..a86dcedd7e 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -842,4 +842,13 @@ describe('typeahead tests', function () { expect($scope.select_count).toEqual(1); }); + describe('minLength set to 0', function () { + it('should open typeahead if input is changed to empty string if defined threshold is 0', function () { + var element = prepareInputEl('
'); + changeInputValueTo(element, ''); + + expect(element).toBeOpenWithActive(3, 0); + }); + }); + }); diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 1fe28401ab..f4cee902ca 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -41,7 +41,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //SUPPORTED ATTRIBUTES (OPTIONS) //minimal no of characters that needs to be entered before typeahead kicks-in - var minSearch = originalScope.$eval(attrs.typeaheadMinLength) || 1; + var minSearch = originalScope.$eval(attrs.typeaheadMinLength); + if (!minSearch && minSearch !== 0) { + minSearch = 1; + } //minimal wait time after last character typed before typeahead kicks-in var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0; @@ -193,7 +196,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap hasFocus = true; - if (inputValue && inputValue.length >= minSearch) { + if (minSearch === 0 || inputValue && inputValue.length >= minSearch) { if (waitTime > 0) { cancelPreviousTimeout(); scheduleSearchWithTimeout(inputValue); From 95334ba70fe7dda6966c4c52fc4b17bb33b09aca Mon Sep 17 00:00:00 2001 From: Joe Ibershoff Date: Thu, 30 Apr 2015 09:17:51 -0400 Subject: [PATCH 2/2] feat(typeahead): handles min-length of 0 (variable cleanup) --- src/typeahead/typeahead.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index f4cee902ca..dba444dcf1 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -41,9 +41,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //SUPPORTED ATTRIBUTES (OPTIONS) //minimal no of characters that needs to be entered before typeahead kicks-in - var minSearch = originalScope.$eval(attrs.typeaheadMinLength); - if (!minSearch && minSearch !== 0) { - minSearch = 1; + var minLength = originalScope.$eval(attrs.typeaheadMinLength); + if (!minLength && minLength !== 0) { + minLength = 1; } //minimal wait time after last character typed before typeahead kicks-in @@ -196,7 +196,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap hasFocus = true; - if (minSearch === 0 || inputValue && inputValue.length >= minSearch) { + if (minLength === 0 || inputValue && inputValue.length >= minLength) { if (waitTime > 0) { cancelPreviousTimeout(); scheduleSearchWithTimeout(inputValue);