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

Commit

Permalink
fix(typeahead): set validity if model is set manually
Browse files Browse the repository at this point in the history
With this commit, the validity of a typeahead model is set to true if
the model is set manually and the typehead directive is set to be
non-editable.

add test for setting model manually

Fixes #3318
  • Loading branch information
andrenarchy authored and wesleycho committed Mar 23, 2015
1 parent 03446c5 commit b004443
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<div><form name="form">' +
'<input name="input" ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-editable="false">' +
'</form></div>');

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 () {
Expand Down
7 changes: 7 additions & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b004443

Please sign in to comment.