From 5f3d3ee780813051d912e908c026fd753fc7b6be Mon Sep 17 00:00:00 2001 From: germannj Date: Fri, 29 Jan 2016 12:59:45 +0100 Subject: [PATCH 1/3] add support for changing typeaheadMinLength One might want to change minLength no of characters condition based. --- src/typeahead/typeahead.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index acc7d1df75..3c99b4a060 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -38,7 +38,14 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap if (!minLength && minLength !== 0) { minLength = 1; } - + originalScope.$watch(attrs.typeaheadMinLength, function (newVal) { + if (!newVal && newVal !== 0) { + minLength = 1; + } else { + minLength = newVal; + } + }); + //minimal wait time after last character typed before typeahead kicks-in var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0; From 4b73d61e06587e65694315af5676c60ee97c8c7f Mon Sep 17 00:00:00 2001 From: germannj Date: Mon, 1 Feb 2016 08:57:45 +0100 Subject: [PATCH 2/3] use ternary as suggested by wesleycho --- src/typeahead/typeahead.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 3c99b4a060..c2b34159b5 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -39,11 +39,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap minLength = 1; } originalScope.$watch(attrs.typeaheadMinLength, function (newVal) { - if (!newVal && newVal !== 0) { - minLength = 1; - } else { - minLength = newVal; - } + minLength = !newVal && newVal !== 0 ? 1 : newVal; }); //minimal wait time after last character typed before typeahead kicks-in From d6f0058aa513cb75fde1d0372f225842224c5151 Mon Sep 17 00:00:00 2001 From: Jonathan Germann Date: Wed, 3 Feb 2016 11:50:29 +0100 Subject: [PATCH 3/3] feat(typeahead): add test for changing min length --- src/typeahead/test/typeahead.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index a6d7db188e..d15d1e9860 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -196,6 +196,24 @@ describe('typeahead tests', function() { expect(element).toBeClosed(); }); + + it('should support changing min-length', function() { + $scope.typeAheadMinLength = 2; + var element = prepareInputEl('
'); + changeInputValueTo(element, 'b'); + expect(element).toBeClosed(); + $scope.typeAheadMinLength = 0; + $scope.$digest(); + changeInputValueTo(element, ''); + expect(element).toBeOpenWithActive(3, 0); + $scope.typeAheadMinLength = 2; + $scope.$digest(); + changeInputValueTo(element, 'b'); + expect(element).toBeClosed(); + }); + + + it('should support custom model selecting function', function() { $scope.updaterFn = function(selectedItem) { return 'prefix' + selectedItem;