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

Commit

Permalink
feat(typeahead): add dynamic min length support
Browse files Browse the repository at this point in the history
- Add support for dynamically changed min length

Closes #5363
  • Loading branch information
germannj authored and wesleycho committed Feb 3, 2016
1 parent 42fb486 commit f81d440
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Expand Up @@ -196,6 +196,30 @@ describe('typeahead tests', function() {
expect(element).toBeClosed();
});


it('should support changing min-length', function() {
$scope.typeAheadMinLength = 2;
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-min-length="typeAheadMinLength"></div>');

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;
Expand Down
4 changes: 4 additions & 0 deletions src/typeahead/typeahead.js
Expand Up @@ -39,6 +39,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
minLength = 1;
}

originalScope.$watch(attrs.typeaheadMinLength, function (newVal) {
minLength = !newVal && newVal !== 0 ? 1 : newVal;
});

//minimal wait time after last character typed before typeahead kicks-in
var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0;

Expand Down

0 comments on commit f81d440

Please sign in to comment.