Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selected object updates when deleting entire highlighted selection #493

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions angucomplete-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
}
else if (which === KEY_DW) {
event.preventDefault();
if (!scope.showDropdown && scope.searchStr && scope.searchStr.length >= minlength) {
if (!scope.showDropdown && scope.searchStr && scope.searchStr.length >= parseInt(minlength)) {
initResults();
scope.searching = true;
searchTimerComplete(scope.searchStr);
Expand All @@ -268,13 +268,9 @@
});
}
else {
if (minlength === 0 && !scope.searchStr) {
return;
}

if (!scope.searchStr || scope.searchStr === '') {
if (parseInt(minlength) > 0 && (!scope.searchStr || scope.searchStr === '')) {
scope.showDropdown = false;
} else if (scope.searchStr.length >= minlength) {
} else if (!scope.searchStr || (scope.searchStr && scope.searchStr.length >= parseInt(minlength))) {
initResults();

if (searchTimer) {
Expand Down Expand Up @@ -405,11 +401,10 @@
handleOverrideSuggestions();
}
else {
if (scope.currentIndex === -1) {
scope.currentIndex = 0;
}
scope.selectResult(scope.results[scope.currentIndex]);
scope.$digest();
if(scope.currentIndex >= 0) {
scope.selectResult(scope.results[scope.currentIndex]);
scope.$digest();
}
}
}
else {
Expand Down Expand Up @@ -551,7 +546,7 @@

function searchTimerComplete(str) {
// Begin the search
if (!str || str.length < minlength) {
if (parseInt(minlength) > 0 && (!str || str.length < parseInt(minlength))) {
return;
}
if (scope.localData) {
Expand Down Expand Up @@ -641,7 +636,7 @@
if (scope.focusIn) {
scope.focusIn();
}
if (minlength === 0 && (!scope.searchStr || scope.searchStr.length === 0)) {
if (parseInt(minlength) === 0 && (!scope.searchStr || scope.searchStr.length === 0)) {
scope.currentIndex = scope.focusFirst ? 0 : scope.currentIndex;
scope.showDropdown = true;
showAll();
Expand Down Expand Up @@ -698,18 +693,18 @@
scope.searchStr = null;
}
else {
scope.searchStr = result.title;
scope.searchStr = result ? result.title : undefined;
}
callOrAssign(result);
clearResults();
};

scope.inputChangeHandler = function(str) {
if (str.length < minlength) {
if (str.length < parseInt(minlength)) {
cancelHttpRequest();
clearResults();
}
else if (str.length === 0 && minlength === 0) {
else if (str.length === 0 && parseInt(minlength) === 0) {
showAll();
}

Expand Down
5 changes: 2 additions & 3 deletions test/angucomplete-alt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ describe('angucomplete-alt', function() {
$httpBackend.verifyNoOutstandingRequest();
}));

it('should remove highlight when input becomes empty', function() {
it('should not 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;
$scope.countries = [
Expand Down Expand Up @@ -1670,7 +1670,7 @@ describe('angucomplete-alt', function() {
element.find('.angucomplete-row .highlight').each(function() {
expect($(this).text().length).toBe(0);
});
expect(element.find('.angucomplete-row').length).toBe(3);
expect(element.find('.angucomplete-row').length).toBe(0);
});

it('should set $scope.searching to true when input becomes empty and using remote data', inject(function($httpBackend) {
Expand All @@ -1694,7 +1694,6 @@ describe('angucomplete-alt', function() {

expect(element.isolateScope().searching).toBe(true);

$timeout.flush();
$httpBackend.flush();

expect(element.isolateScope().searching).toBe(false);
Expand Down