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

Commit 006986d

Browse files
fix(typeahead): do not set editable error when input is empty
Closes #1038
1 parent 0b5ca78 commit 006986d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/typeahead/test/typeahead.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ describe('typeahead tests', function () {
185185
expect($scope.form.input.$error.editable).toBeFalsy();
186186
});
187187

188+
it('should not set editable validation error for empty input', function () {
189+
var element = prepareInputEl(
190+
"<div><form name='form'>" +
191+
"<input name='input' ng-model='result' typeahead='item for item in source | filter:$viewValue' typeahead-editable='false'>" +
192+
"</form></div>");
193+
194+
changeInputValueTo(element, 'not in matches');
195+
expect($scope.result).toEqual(undefined);
196+
expect($scope.form.input.$error.editable).toBeTruthy();
197+
changeInputValueTo(element, '');
198+
expect($scope.result).toEqual('');
199+
expect($scope.form.input.$error.editable).toBeFalsy();
200+
});
201+
188202
it('should bind loading indicator expression', inject(function ($timeout) {
189203

190204
$scope.isLoading = false;

src/typeahead/typeahead.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
162162
if (isEditable) {
163163
return inputValue;
164164
} else {
165-
modelCtrl.$setValidity('editable', false);
166-
return undefined;
165+
if (!inputValue) {
166+
// Reset in case user had typed something previously.
167+
modelCtrl.$setValidity('editable', true);
168+
return inputValue;
169+
} else {
170+
modelCtrl.$setValidity('editable', false);
171+
return undefined;
172+
}
167173
}
168174
});
169175

0 commit comments

Comments
 (0)