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

Commit bc7c55a

Browse files
mabiwesleycho
authored andcommitted
fix(typeahead): reset errors when clearing
- Reset validation errors when clearing Closes #5641
1 parent 316e96c commit bc7c55a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ describe('typeahead tests', function() {
202202

203203

204204
it('should support changing min-length', function() {
205-
$scope.typeAheadMinLength = 2;
205+
$scope.typeAheadMinLength = 2;
206206
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-min-length="typeAheadMinLength"></div>');
207207

208208
changeInputValueTo(element, 'b');
@@ -299,6 +299,22 @@ describe('typeahead tests', function() {
299299
expect(inputEl.val()).toEqual('');
300300
});
301301

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();
313+
314+
expect($scope.form.input.$error.editable).toBeFalsy();
315+
expect($scope.form.input.$error.parse).toBeFalsy();
316+
});
317+
302318
it('should clear view value when no value selected for typeahead-editable="false" typeahead-select-on-blur="false"', function () {
303319
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>');
304320
var inputEl = findInput(element);

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)