diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 8f2c7323c1..d83571a7c8 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -630,6 +630,16 @@ describe('typeahead tests', function () { $(match).click(); $scope.$digest(); }); + + it('issue #3166 - should set \'parse\' key as valid when selecting a perfect match and not editable', function () { + var element = prepareInputEl('
'); + var inputEl = findInput(element); + + changeInputValueTo(element, 'Alaska'); + triggerKeyDown(element, 13); + + expect($scope.test.typeahead.$error.parse).toBeUndefined(); + }); }); describe('input formatting', function () { @@ -741,7 +751,7 @@ describe('typeahead tests', function () { }; var element = prepareInputEl('
'); changeInputValueTo(element, 'b'); - + // enter key should not be captured when nothing is focused triggerKeyDown(element, 13); expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy(); diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 06baa1be81..cc4b889c0b 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -172,7 +172,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //we need to propagate user's query so we can higlight matches scope.query = undefined; - //Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later + //Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later var timeoutPromise; var scheduleSearchWithTimeout = function(inputValue) { @@ -252,6 +252,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap model = parserResult.modelMapper(originalScope, locals); $setModelValue(originalScope, model); modelCtrl.$setValidity('editable', true); + modelCtrl.$setValidity('parse', true); onSelectCallback(originalScope, { $item: item, @@ -326,7 +327,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap }); var $popup = $compile(popUpEl)(scope); - + if (appendToBody) { $document.find('body').append($popup); } else {