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

Commit 72c87b9

Browse files
committed
fix(typeahead): reset errors when clearing
1 parent e640966 commit 72c87b9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,21 @@ describe('typeahead tests', function() {
298298
expect($scope.result).toEqual(undefined);
299299
expect(inputEl.val()).toEqual('');
300300
});
301+
302+
it('should clear errors after blur for typeahead-editable="false"', function () {
303+
var element = prepareInputEl(
304+
'<div><form name="form">' +
305+
'<input name="input" ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false">' +
306+
'</form></div>');
307+
var inputEl = findInput(element);
308+
309+
changeInputValueTo(element, 'not in matches');
310+
expect($scope.result).toEqual(undefined);
311+
expect(inputEl.val()).toEqual('not in matches');
312+
inputEl.blur(); // input loses focus
313+
expect($scope.form.input.$error.editable).toBeFalsy();
314+
expect($scope.form.input.$error.parse).toBeFalsy();
315+
});
301316

302317
it('should clear view value when no value selected for typeahead-editable="false" typeahead-select-on-blur="false"', function () {
303318
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false" typeahead-select-on-blur="false"></div>');

Diff for: src/typeahead/typeahead.js

+3
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
442442
}
443443
if (!isEditable && modelCtrl.$error.editable) {
444444
modelCtrl.$viewValue = '';
445+
// Reset validity as we are clearing
446+
modelCtrl.$setValidity('editable', true);
447+
modelCtrl.$setValidity('parse', true);
445448
element.val('');
446449
}
447450
hasFocus = false;

0 commit comments

Comments
 (0)