From 4349163ae1fc90f83a3d9d21a89cc1d4f1350afe Mon Sep 17 00:00:00 2001 From: mbisioli Date: Wed, 16 Mar 2016 12:58:41 +0100 Subject: [PATCH] fix(typeahead): reset errors when clearing --- src/typeahead/test/typeahead.spec.js | 15 +++++++++++++++ src/typeahead/typeahead.js | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 850215e5ae..e65a6d98e7 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -298,6 +298,21 @@ describe('typeahead tests', function() { expect($scope.result).toEqual(undefined); expect(inputEl.val()).toEqual(''); }); + + it('should clear errors after blur for typeahead-editable="false"', function () { + var element = prepareInputEl( + '
' + + '' + + '
'); + var inputEl = findInput(element); + + changeInputValueTo(element, 'not in matches'); + expect($scope.result).toEqual(undefined); + expect(inputEl.val()).toEqual('not in matches'); + inputEl.blur(); // input loses focus + expect($scope.form.input.$error.editable).toBeFalsy(); + expect($scope.form.input.$error.parse).toBeFalsy(); + }); it('should clear view value when no value selected for typeahead-editable="false" typeahead-select-on-blur="false"', function () { var element = prepareInputEl('
'); diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index f364bcee81..14169c6371 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -442,6 +442,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap } if (!isEditable && modelCtrl.$error.editable) { modelCtrl.$viewValue = ''; + // Reset validity as we are clearing + modelCtrl.$setValidity('editable', true); + modelCtrl.$setValidity('parse', true); element.val(''); } hasFocus = false;