From c0a9c707903fa3dfc662887cd348ee2b0bf13f85 Mon Sep 17 00:00:00 2001 From: Daniel Zimmermann Date: Thu, 19 Mar 2015 12:51:50 +1100 Subject: [PATCH] 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 --- src/typeahead/test/typeahead.spec.js | 10 ++++++++++ src/typeahead/typeahead.js | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index fb801d4871..6dbdf38176 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -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('
'); + var inputEl = findInput(element); + + changeInputValueTo(element, 'Alaska'); + triggerKeyDown(element, 13); + + expect($scope.test.typeahead.$error.parse).toBeUndefined(); + }); }); describe('input formatting', function () { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 63f196edfc..af786e010a 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -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, @@ -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 {