diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 587f51fff9..34a3fbb1fb 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -18,15 +18,24 @@ var libtoaster = (function (){ if (!xhrUrl || xhrUrl.length === 0) throw("No url to typeahead supplied"); + var xhrReq; + jQElement.typeahead({ source: function(query, process){ xhrParams.search = query; - $.getJSON(xhrUrl, this.options.xhrParams, function(data){ + + /* If we have a request in progress don't fire off another one*/ + if (xhrReq) + xhrReq.abort(); + + xhrReq = $.getJSON(xhrUrl, this.options.xhrParams, function(data){ if (data.error !== "ok") { console.log("Error getting data from server "+data.error); return; } + xhrReq = null; + return process(data.results); }); }, @@ -41,6 +50,9 @@ var libtoaster = (function (){ return 0; } + if (this.$element.val().length === 0) + return 0; + return 1; }, highlighter: function (item) { @@ -52,6 +64,7 @@ var libtoaster = (function (){ sorter: function (items) { return items; }, xhrUrl: xhrUrl, xhrParams: xhrParams, + xhrReq: xhrReq, }); @@ -528,6 +541,9 @@ $(document).ready(function() { }); $(document).ajaxError(function(event, jqxhr, settings, errMsg){ + if (errMsg === 'abort') + return; + console.warn("Problem with xhr call"); console.warn(errMsg); console.warn(jqxhr.responseText);