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

Commit

Permalink
fix(typeahead): reset 'parse' validation key
Browse files Browse the repository at this point in the history
When typeahead-editable="false" and we select a perfect
match from the results list, the $parsers aren't called,
which results in the 'parse' error key not being reset.

As with the 'editable' key, we should reset this once
an item is selected because we know we have a valid
model matching the view value.

Closes #3166
  • Loading branch information
dlukez authored and Wesley Cho committed Mar 23, 2015
1 parent 405dab6 commit c0a9c70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ describe('typeahead tests', function () {
expect($scope.result).toEqual('manually set');
expect($scope.form.input.$valid).toBeTruthy();
});

it('issue #3166 - should set \'parse\' key as valid when selecting a perfect match and not editable', function () {
var element = prepareInputEl('<div ng-form="test"><input name="typeahead" ng-model="result" typeahead="state as state.name for state in states | filter:$viewValue" typeahead-editable="false"></div>');
var inputEl = findInput(element);

changeInputValueTo(element, 'Alaska');
triggerKeyDown(element, 13);

expect($scope.test.typeahead.$error.parse).toBeUndefined();
});
});

describe('input formatting', function () {
Expand Down
3 changes: 2 additions & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,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,
Expand Down Expand Up @@ -333,7 +334,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
});

var $popup = $compile(popUpEl)(scope);

if (appendToBody) {
$document.find('body').append($popup);
} else {
Expand Down

0 comments on commit c0a9c70

Please sign in to comment.