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

Commit

Permalink
fix(typeahead): loading callback updates after blur
Browse files Browse the repository at this point in the history
Fixes #1822
Closes #1904
  • Loading branch information
Michal Charemza authored and pkozlowski-opensource committed Mar 8, 2014
1 parent c6c0e2d commit 6a83011
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,25 @@ describe('typeahead tests', function () {
expect(element).toBeClosed();
});

it('should properly update loading callback if an element is not focused', function () {

$scope.items = function(viewValue) {
return $timeout(function(){
return [viewValue];
});
};
var element = prepareInputEl('<div><input ng-model="result" typeahead-loading="isLoading" typeahead="item for item in items($viewValue)"></div>');
var inputEl = findInput(element);

changeInputValueTo(element, 'match');
$scope.$digest();

inputEl.blur();
$timeout.flush();

expect($scope.isLoading).toBeFalsy();
});

it('issue 1140 - should properly update loading callback when deleting characters', function () {

$scope.items = function(viewValue) {
Expand Down
5 changes: 4 additions & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

//it might happen that several async queries were in progress if a user were typing fast
//but we are interested only in responses that correspond to the current view value
if (inputValue === modelCtrl.$viewValue && hasFocus) {
var onCurrentRequest = (inputValue === modelCtrl.$viewValue);
if (onCurrentRequest && hasFocus) {
if (matches.length > 0) {

scope.activeIdx = 0;
Expand All @@ -136,6 +137,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
} else {
resetMatches();
}
}
if (onCurrentRequest) {
isLoadingSetter(originalScope, false);
}
}, function(){
Expand Down

0 comments on commit 6a83011

Please sign in to comment.