From 9acfc6faa5448730cb5e82f2277b80080df3d7f5 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Thu, 14 Mar 2013 12:47:46 -0700 Subject: [PATCH] prevent duplicate queries --- select2.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/select2.js b/select2.js index ca8b974c..8d295c7b 100644 --- a/select2.js +++ b/select2.js @@ -1349,7 +1349,17 @@ the specific language governing permissions and limitations under the Apache Lic */ // abstract updateResults: function (initial) { - var search = this.search, results = this.results, opts = this.opts, data, self=this, input; + var search = this.search, + results = this.results, + opts = this.opts, + data, + self = this, + input, + term = search.val(), + lastTerm=$.data(this.container, "select2-last-term"); + + // prevent duplicate queries against the same term + if (initial !== true && lastTerm && equal(term, lastTerm)) return; // if the search is currently hidden we do not alter the results if (initial !== true && (this.showSearchInput === false || !this.opened())) { @@ -1408,6 +1418,8 @@ the specific language governing permissions and limitations under the Apache Lic this.resultsPage = 1; + $.data(this.container, "select2-last-term", term); + opts.query({ element: opts.element, term: search.val(),