I had a problem with my SQL, I was selecting from two different databases and using union to merge the results, however for the first selection I had forgotten to include a where statement so all results were taken from there. As I had put a limit of 10 items no other results could be displayed.
JQuery UI Autocomplete searches the same respose
-
19-10-2022 - |
Question
I'm having a problem with Autocomplete. I can do an initial search fine but if I want to search in the same input again it only searches the previously returned results, if I try to check if any there were any results the response ui object at this point throws an error:
Uncaught TypeError: Cannot read property 'length' of null.
I have to reload the page to be able to search again with the autocomplete, how can I fix this?
jQuery(this).autocomplete({
autoFocus: true,
response: function (event, ui) {
if (ui.content.length === 0) {
console.log("No results found");
} else {
console.log(ui.content.length + " results were found");
}
},
source: "index.php?option=com_casehandler&format=raw&task=autocomplete&table=" + table + "&column=" + column + "&term=" + jQuery(this).val(),
minLength: 0,
delay: 500,
search: function () {
console.log('searching...' + "index.php?option=com_casehandler&format=raw&task=autocomplete&table=" + table + "&column=" + column + "&term=" + jQuery(this).val());
jQuery(this).data().term = null;
},
select: function (event, ui) {
jQuery(this).val(ui.item.value);
}
});
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow