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

Commit

Permalink
fix(typeahead): do not set editable error when input is empty
Browse files Browse the repository at this point in the history
Closes #1038
  • Loading branch information
ianjosephwilson authored and pkozlowski-opensource committed Sep 19, 2013
1 parent 0b5ca78 commit 006986d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ describe('typeahead tests', function () {
expect($scope.form.input.$error.editable).toBeFalsy();
});

it('should not set editable validation error for empty input', function () {
var element = prepareInputEl(
"<div><form name='form'>" +
"<input name='input' ng-model='result' typeahead='item for item in source | filter:$viewValue' typeahead-editable='false'>" +
"</form></div>");

changeInputValueTo(element, 'not in matches');
expect($scope.result).toEqual(undefined);
expect($scope.form.input.$error.editable).toBeTruthy();
changeInputValueTo(element, '');
expect($scope.result).toEqual('');
expect($scope.form.input.$error.editable).toBeFalsy();
});

it('should bind loading indicator expression', inject(function ($timeout) {

$scope.isLoading = false;
Expand Down
10 changes: 8 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,14 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
if (isEditable) {
return inputValue;
} else {
modelCtrl.$setValidity('editable', false);
return undefined;
if (!inputValue) {
// Reset in case user had typed something previously.
modelCtrl.$setValidity('editable', true);
return inputValue;
} else {
modelCtrl.$setValidity('editable', false);
return undefined;
}
}
});

Expand Down

0 comments on commit 006986d

Please sign in to comment.