diff --git a/angucomplete-alt.js b/angucomplete-alt.js index 52459092..5c566f04 100644 --- a/angucomplete-alt.js +++ b/angucomplete-alt.js @@ -621,12 +621,15 @@ function showAll() { if (scope.localData) { + scope.searching = false; processResults(scope.localData, ''); } else if (scope.remoteApiHandler) { + scope.searching = true; getRemoteResultsWithCustomHandler(''); } else { + scope.searching = true; getRemoteResults(''); } } @@ -704,7 +707,6 @@ clearResults(); } else if (str.length === 0 && minlength === 0) { - scope.searching = false; showAll(); } diff --git a/test/angucomplete-alt.spec.js b/test/angucomplete-alt.spec.js index 4858e258..ab2cd7f5 100644 --- a/test/angucomplete-alt.spec.js +++ b/test/angucomplete-alt.spec.js @@ -1611,6 +1611,27 @@ describe('angucomplete-alt', function() { expect(element.find('.angucomplete-row').length).toBe(3); }); + it('should set $scope.searching to true on focus when using remote data', inject(function($httpBackend) { + var element = angular.element('
'); + $compile(element)($scope); + $scope.$digest(); + + var results = {data: []}; + $httpBackend.expectGET('names?q=').respond(200, results); + + var inputField = element.find('#ex1_value'); + inputField.triggerHandler('focus'); + $scope.$digest(); + expect(element.isolateScope().searching).toBe(true); + + $timeout.flush(); + $httpBackend.flush(); + + expect(element.isolateScope().searching).toBe(false); + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + })); + it('should remove highlight when input becomes empty', function() { var element = angular.element(''); $scope.countrySelected = null; @@ -1651,6 +1672,35 @@ describe('angucomplete-alt', function() { }); expect(element.find('.angucomplete-row').length).toBe(3); }); + + it('should set $scope.searching to true when input becomes empty and using remote data', inject(function($httpBackend) { + var element = angular.element(''); + $compile(element)($scope); + $scope.$digest(); + + var results = {data: []}; + $httpBackend.expectGET('names?q=').respond(200, results); + + var inputField = element.find('#ex1_value'); + inputField.val('a'); + $scope.$digest(); + + var eKeyup = $.Event('keyup'); + eKeyup.which = KEY_DEL; + inputField.val(''); + inputField.triggerHandler('input'); + inputField.trigger(eKeyup); + $scope.$digest(); + + expect(element.isolateScope().searching).toBe(true); + + $timeout.flush(); + $httpBackend.flush(); + + expect(element.isolateScope().searching).toBe(false); + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + })); }); describe('Numeric data', function() {