Clear answer when nothing is found

This commit is contained in:
Martin Potier 2015-09-20 17:26:32 +02:00
parent bd6256d8ee
commit 3311dfd997
1 changed files with 11 additions and 5 deletions

View File

@ -227,6 +227,9 @@ function main() {
//}); //});
$( "#question" ).keyup(function (e) { $( "#question" ).keyup(function (e) {
if (e.key != "ArrowDown") {
currentSelection = 0;
}
var str = removeDiacritics($( "#question" ).val()); var str = removeDiacritics($( "#question" ).val());
var cleanstr = str ? str.trim() : null; var cleanstr = str ? str.trim() : null;
if (str == "" || str == null) { if (str == "" || str == null) {
@ -234,16 +237,19 @@ function main() {
$( "#answerTable" ).empty(); $( "#answerTable" ).empty();
return; return;
} }
$( "#answerTable" ).empty().append(title);
var ans = words.find({'Word': { '$contains': cleanstr }}); var ans = words.find({'Word': { '$contains': cleanstr }});
$( "#answerTable" ).empty();
if (ans.length > 0) { if (ans.length > 0) {
if (e.key == "ArrowDown") { if (e.key == "ArrowDown") {
currentSelection = (currentSelection + 1) % Math.min(maxNbRes,ans.length); currentSelection =
} else { (currentSelection + 1) % Math.min(maxNbRes,ans.length);
currentSelection = 0;
} }
$( "#proposition" ).empty().append(listMany(ans,currentSelection)); $( "#proposition" ).empty().append(listMany(ans,currentSelection));
$( "#answerTable" ).append(displayOne(ans[currentSelection])); $( "#answerTable" ).append(title+displayOne(ans[currentSelection]));
} else {
$( "#answerTable" ).empty();
$( "#proposition" ).empty();
} }
}); });
} }