From 9c33b3ad32f7cc4fbd209c874ca33bc8657f05bc Mon Sep 17 00:00:00 2001 From: Joe Ibershoff Date: Mon, 20 Jan 2014 16:12:09 -0500 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, 13 insertions(+), 3 deletions(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index c8c2b4d1d9..7a6dac107e 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -594,4 +594,13 @@ describe('typeahead tests', function () { }); }); + 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); + }); + }); + }); \ No newline at end of file diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 3aa213e79c..1296105482 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -41,7 +41,8 @@ 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); + minSearch = minSearch === 0 ? minSearch : minSearch || 1; //minimal wait time after last character typed before typehead kicks-in var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0; @@ -150,7 +151,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) { if (timeoutPromise) { $timeout.cancel(timeoutPromise);//cancel previous timeout @@ -221,7 +222,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap resetMatches(); - //return focus to the input element if a mach was selected via a mouse click event + //return focus to the input element if a match was selected via a mouse click event element[0].focus(); }; From 30bf430783cca03c5b87aed735244c4c00f0955e Mon Sep 17 00:00:00 2001 From: Joe Ibershoff Date: Mon, 20 Jan 2014 16:12:09 -0500 Subject: [PATCH 2/2] feat(typeahead): handles min-length of 0