Skip to content

Commit

Permalink
Closes #121. When ajax returns no data, item list disappears.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelczak authored and pawelczak committed Nov 5, 2015
1 parent c18782f commit 0b24760
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
10 changes: 4 additions & 6 deletions dist/jquery.easy-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -1352,17 +1352,15 @@ var EasyAutocomplete = (function(scope) {
listBuilders = listBuilderService.updateCategories(listBuilders, data);

listBuilders = listBuilderService.convertXml(listBuilders);


if (!listBuilderService.checkIfDataExists(listBuilders)) {
return;
}
if (checkInputPhraseMatchResponse(inputPhrase, data)) {

listBuilders = listBuilderService.processData(listBuilders, inputPhrase);

loadElements(listBuilders, inputPhrase);


}

if (listBuilderService.checkIfDataExists(listBuilders)) {
showContainer();
}

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.easy-autocomplete.min.js

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,16 @@ var EasyAutocomplete = (function(scope) {
listBuilders = listBuilderService.convertXml(listBuilders);


if (!listBuilderService.checkIfDataExists(listBuilders)) {
return;
}


//Todo
//TODO
if (checkInputPhraseMatchResponse(inputPhrase, data)) {

listBuilders = listBuilderService.processData(listBuilders, inputPhrase);

loadElements(listBuilders, inputPhrase);


}

if (listBuilderService.checkIfDataExists(listBuilders)) {
showContainer();
}

Expand Down
51 changes: 51 additions & 0 deletions test/core/response_remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,57 @@ QUnit.test("Remote service - Json countries", function( assert ) {
}
});

QUnit.test("Remote service - Json countries - no match", function( assert ) {
expect(1);

//given
var completerOne = new EasyAutocomplete.main($("#inputOne"), {

url: function(phrase) {
return "remote/countrySelectService.php?phrase=" + phrase + "&dataType=json";
},

getValue: function(element) {
return element.name;
},

ajaxCallback: function() {

//assert

assertList();
},
list: {
match: {
enabled: true
}
}

});


//execute

completerOne.init();

var e = $.Event('keyup');
e.keyCode = 50;
$("#inputOne").val("poli").trigger(e);


QUnit.stop();

//assert

function assertList() {
var elements = $("#inputOne").next().find("ul li");

assert.equal(0, elements.length, "Response size");

QUnit.start();
}
});

QUnit.test("Remote service - XML countries", function( assert ) {
expect(5);

Expand Down

0 comments on commit 0b24760

Please sign in to comment.