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

Commit 6a83011

Browse files
Michal Charemzapkozlowski-opensource
Michal Charemza
authored andcommitted
fix(typeahead): loading callback updates after blur
Fixes #1822 Closes #1904
1 parent c6c0e2d commit 6a83011

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/typeahead/test/typeahead.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,25 @@ describe('typeahead tests', function () {
507507
expect(element).toBeClosed();
508508
});
509509

510+
it('should properly update loading callback if an element is not focused', function () {
511+
512+
$scope.items = function(viewValue) {
513+
return $timeout(function(){
514+
return [viewValue];
515+
});
516+
};
517+
var element = prepareInputEl('<div><input ng-model="result" typeahead-loading="isLoading" typeahead="item for item in items($viewValue)"></div>');
518+
var inputEl = findInput(element);
519+
520+
changeInputValueTo(element, 'match');
521+
$scope.$digest();
522+
523+
inputEl.blur();
524+
$timeout.flush();
525+
526+
expect($scope.isLoading).toBeFalsy();
527+
});
528+
510529
it('issue 1140 - should properly update loading callback when deleting characters', function () {
511530

512531
$scope.items = function(viewValue) {

src/typeahead/typeahead.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
110110

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

116117
scope.activeIdx = 0;
@@ -136,6 +137,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
136137
} else {
137138
resetMatches();
138139
}
140+
}
141+
if (onCurrentRequest) {
139142
isLoadingSetter(originalScope, false);
140143
}
141144
}, function(){

0 commit comments

Comments
 (0)