Skip to content

Commit

Permalink
Merge pull request ghiden#378 from JaZo/issue-377
Browse files Browse the repository at this point in the history
Show text-searching on focus or when input becomes empty with minlength=0
  • Loading branch information
ghiden authored Aug 27, 2016
2 parents 8b3a2cf + 7ebad30 commit 6bbb9f0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
4 changes: 3 additions & 1 deletion angucomplete-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}
}
Expand Down Expand Up @@ -704,7 +707,6 @@
clearResults();
}
else if (str.length === 0 && minlength === 0) {
scope.searching = false;
showAll();
}

Expand Down
50 changes: 50 additions & 0 deletions test/angucomplete-alt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div angucomplete-alt id="ex1" placeholder="Search names" selected-object="selected" remote-url="names?q=" search-fields="name" remote-url-data-field="data" title-field="name" minlength="0"/>');
$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('<div angucomplete-alt id="ex1" placeholder="Search countries" selected-object="countrySelected" local-data="countries" search-fields="name" title-field="name" minlength="0" match-class="highlight"/>');
$scope.countrySelected = null;
Expand Down Expand Up @@ -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('<div angucomplete-alt id="ex1" placeholder="Search names" selected-object="selected" remote-url="names?q=" search-fields="name" remote-url-data-field="data" title-field="name" minlength="0"/>');
$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() {
Expand Down

0 comments on commit 6bbb9f0

Please sign in to comment.