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

add support for changing typeaheadMinLength #5363

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ 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
5 changes: 4 additions & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
if (!minLength && minLength !== 0) {
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