Commit 995bd6ad authored by Ryan Herbert's avatar Ryan Herbert

autocomplete.js limit server queries

only query the server if there are more than 2 characters in the query.
If there are less than 3 characters filter on the 10 most recent sets
parent 86af3b90
......@@ -195,8 +195,9 @@ VidjilAutoComplete.prototype = {
callbacks.filter = function(query, data, searchKey) {
var fetchData = self.fetchData.bind(self);
var isLoaded = self.isLoaded.bind(self);
var keys = [this.$inputor.val()];
if (VidjilAutoComplete.isLoading(data) || !isLoaded(keys)) {
var val = this.$inputor.val()
var keys = [val];
if ((VidjilAutoComplete.isLoading(data) || !isLoaded(keys)) && (val.length == 0 || val.length >= 3)) {
this.$inputor.atwho('load', this.at, VidjilAutoComplete.defaultLoadingData);
fetchData(this.$inputor, this.at, keys);
return data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment