Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit f81d440

Browse files
germannjwesleycho
authored andcommitted
feat(typeahead): add dynamic min length support
- Add support for dynamically changed min length Closes #5363
1 parent 42fb486 commit f81d440

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/typeahead/test/typeahead.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,30 @@ describe('typeahead tests', function() {
196196
expect(element).toBeClosed();
197197
});
198198

199+
200+
it('should support changing min-length', function() {
201+
$scope.typeAheadMinLength = 2;
202+
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-min-length="typeAheadMinLength"></div>');
203+
204+
changeInputValueTo(element, 'b');
205+
206+
expect(element).toBeClosed();
207+
208+
$scope.typeAheadMinLength = 0;
209+
$scope.$digest();
210+
changeInputValueTo(element, '');
211+
212+
expect(element).toBeOpenWithActive(3, 0);
213+
214+
$scope.typeAheadMinLength = 2;
215+
$scope.$digest();
216+
changeInputValueTo(element, 'b');
217+
218+
expect(element).toBeClosed();
219+
});
220+
221+
222+
199223
it('should support custom model selecting function', function() {
200224
$scope.updaterFn = function(selectedItem) {
201225
return 'prefix' + selectedItem;

src/typeahead/typeahead.js

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
3939
minLength = 1;
4040
}
4141

42+
originalScope.$watch(attrs.typeaheadMinLength, function (newVal) {
43+
minLength = !newVal && newVal !== 0 ? 1 : newVal;
44+
});
45+
4246
//minimal wait time after last character typed before typeahead kicks-in
4347
var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0;
4448

0 commit comments

Comments
 (0)