diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 7b54ab7b8f..a8d2d16ace 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -650,6 +650,22 @@ describe('typeahead tests', function () { $(match).click(); $scope.$digest(); }); + + it('issue #3318 - should set model validity to true when set manually', function () { + + var element = prepareInputEl( + '
'); + + changeInputValueTo(element, 'not in matches'); + $scope.$apply(function () { + $scope.result = 'manually set'; + }); + + expect($scope.result).toEqual('manually set'); + expect($scope.form.input.$valid).toBeTruthy(); + }); }); describe('input formatting', function () { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index fa27320fa4..e47b6dae5e 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -225,6 +225,13 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap var candidateViewValue, emptyViewValue; var locals = {}; + // The validity may be set to false via $parsers (see above) if + // the model is restricted to selected values. If the model + // is set manually it is considered to be valid. + if (!isEditable) { + modelCtrl.$setValidity('editable', true); + } + if (inputFormatter) { locals.$model = modelValue;