From e4fbf919157a4f135ccf481a579454ac9129c220 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Thu, 16 Aug 2012 23:04:29 -0700 Subject: [PATCH] ignore replies that come in after select2 has been closed. fixes #299 --- select2.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/select2.js b/select2.js index 12a015a6..cfb6c087 100755 --- a/select2.js +++ b/select2.js @@ -1129,6 +1129,10 @@ matcher: this.opts.matcher, callback: this.bind(function (data) { + // ignore a response if the select2 has been closed before it was received + if (!self.opened()) return; + + self.opts.populateResults.call(this, results, data.results, {term: term, page: page, context:context}); if (data.more===true) { @@ -1206,6 +1210,9 @@ callback: this.bind(function (data) { var def; // default choice + // ignore a response if the select2 has been closed before it was received + if (!this.opened()) return; + // save context, if any this.context = (data.context===undefined) ? null : data.context;