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

Commit a5a2514

Browse files
zacronoswesleycho
authored andcommittedJun 11, 2015
feat(typeahead): handles min-length of 0
Closes #3600
1 parent 988336c commit a5a2514

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

Diff for: ‎src/typeahead/test/typeahead.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,13 @@ describe('typeahead tests', function () {
842842
expect($scope.select_count).toEqual(1);
843843
});
844844

845+
describe('minLength set to 0', function () {
846+
it('should open typeahead if input is changed to empty string if defined threshold is 0', function () {
847+
var element = prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-min-length="0"></div>');
848+
changeInputValueTo(element, '');
849+
850+
expect(element).toBeOpenWithActive(3, 0);
851+
});
852+
});
853+
845854
});

Diff for: ‎src/typeahead/typeahead.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
4141
//SUPPORTED ATTRIBUTES (OPTIONS)
4242

4343
//minimal no of characters that needs to be entered before typeahead kicks-in
44-
var minSearch = originalScope.$eval(attrs.typeaheadMinLength) || 1;
44+
var minLength = originalScope.$eval(attrs.typeaheadMinLength);
45+
if (!minLength && minLength !== 0) {
46+
minLength = 1;
47+
}
4548

4649
//minimal wait time after last character typed before typeahead kicks-in
4750
var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0;
@@ -193,7 +196,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
193196

194197
hasFocus = true;
195198

196-
if (inputValue && inputValue.length >= minSearch) {
199+
if (minLength === 0 || inputValue && inputValue.length >= minLength) {
197200
if (waitTime > 0) {
198201
cancelPreviousTimeout();
199202
scheduleSearchWithTimeout(inputValue);

0 commit comments

Comments
 (0)
This repository has been archived.