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

Commit

Permalink
fix(typeahead): reset errors when clearing
Browse files Browse the repository at this point in the history
- Reset validation errors when clearing

Closes #5641
  • Loading branch information
mabi authored and wesleycho committed Mar 17, 2016
1 parent 316e96c commit bc7c55a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('typeahead tests', function() {


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

changeInputValueTo(element, 'b');
Expand Down Expand Up @@ -299,6 +299,22 @@ describe('typeahead tests', function() {
expect(inputEl.val()).toEqual('');
});

it('should clear errors after blur for typeahead-editable="false"', function () {
var element = prepareInputEl(
'<div><form name="form">' +
'<input name="input" ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false">' +
'</form></div>');
var inputEl = findInput(element);

changeInputValueTo(element, 'not in matches');
expect($scope.result).toEqual(undefined);
expect(inputEl.val()).toEqual('not in matches');
inputEl.blur();

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('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false" typeahead-select-on-blur="false"></div>');
var inputEl = findInput(element);
Expand Down
3 changes: 3 additions & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bc7c55a

Please sign in to comment.