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

Commit c0a9c70

Browse files
dlukezWesley Cho
authored and
Wesley Cho
committed
fix(typeahead): reset 'parse' validation key
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
1 parent 405dab6 commit c0a9c70

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: src/typeahead/test/typeahead.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,16 @@ describe('typeahead tests', function () {
675675
expect($scope.result).toEqual('manually set');
676676
expect($scope.form.input.$valid).toBeTruthy();
677677
});
678+
679+
it('issue #3166 - should set \'parse\' key as valid when selecting a perfect match and not editable', function () {
680+
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>');
681+
var inputEl = findInput(element);
682+
683+
changeInputValueTo(element, 'Alaska');
684+
triggerKeyDown(element, 13);
685+
686+
expect($scope.test.typeahead.$error.parse).toBeUndefined();
687+
});
678688
});
679689

680690
describe('input formatting', function () {

Diff for: src/typeahead/typeahead.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
259259
model = parserResult.modelMapper(originalScope, locals);
260260
$setModelValue(originalScope, model);
261261
modelCtrl.$setValidity('editable', true);
262+
modelCtrl.$setValidity('parse', true);
262263

263264
onSelectCallback(originalScope, {
264265
$item: item,
@@ -333,7 +334,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
333334
});
334335

335336
var $popup = $compile(popUpEl)(scope);
336-
337+
337338
if (appendToBody) {
338339
$document.find('body').append($popup);
339340
} else {

0 commit comments

Comments
 (0)