diff --git a/src/typeahead/docs/readme.md b/src/typeahead/docs/readme.md index ac7fdc4f3f..114115fb42 100644 --- a/src/typeahead/docs/readme.md +++ b/src/typeahead/docs/readme.md @@ -45,7 +45,7 @@ The typeahead directives provide several attributes: * `typeahead-min-length` _(Defaults: 1)_ : - Minimal no of characters that needs to be entered before typeahead kicks-in. Must be greater than or equal to 1. + Minimal no of characters that needs to be entered before typeahead kicks-in. Must be greater than or equal to 0. * `typeahead-no-results` _(Defaults: angular.noop)_ : diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 55d34a1568..547a44b5be 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -1204,6 +1204,14 @@ describe('typeahead tests', function() { changeInputValueTo(element, ''); expect(element).toBeOpenWithActive(3, 0); }); + + it('should open typeahead when input is focused and value is empty if defined threshold is 0', function () { + var element = prepareInputEl('
'); + var inputEl = findInput(element); + inputEl.focus(); + $scope.$digest(); + expect(element).toBeOpenWithActive(3, 0); + }); }); describe('event listeners', function() { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index e94635858d..1ed9cedd54 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -385,6 +385,13 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) } }); + element.bind('focus', function () { + hasFocus = true; + if (minLength === 0 && !modelCtrl.$viewValue) { + getMatchesAsync(modelCtrl.$viewValue); + } + }); + element.bind('blur', function() { if (isSelectOnBlur && scope.matches.length && scope.activeIdx !== -1 && !selected) { selected = true; @@ -393,7 +400,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) }); } if (!isEditable && modelCtrl.$error.editable) { - element.val(''); + modelCtrl.$viewValue = ''; + element.val(''); } hasFocus = false; selected = false;