From c1f338cfbf53be4217d47482bfc0a7f309d6ffce Mon Sep 17 00:00:00 2001 From: Valdas Petrulis Date: Thu, 23 Oct 2014 10:04:39 +0300 Subject: [PATCH] Dont update the results if the term hasn't changed. https://github.com/ivaynberg/select2/issues/2751 --- select2.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index ae04f1a4..09c37cc1 100644 --- a/select2.js +++ b/select2.js @@ -1500,20 +1500,24 @@ the specific language governing permissions and limitations under the Apache Lic }, /** + * @return {Boolean} Whether or not search value was changed. * @private */ prefillNextSearchTerm: function () { // initializes search's value with nextSearchTerm (if defined by user) // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter if(this.search.val() !== "") { - return; + return false; } var nextSearchTerm = this.opts.nextSearchTerm(this.data(), this.lastSearchTerm); - if(nextSearchTerm != undefined){ + if(nextSearchTerm !== undefined){ this.search.val(nextSearchTerm); this.search.select(); + return true; } + + return false; }, //abstract @@ -3013,8 +3017,9 @@ the specific language governing permissions and limitations under the Apache Lic this.updateResults(true); } else { // initializes search's value with nextSearchTerm and update search result - this.prefillNextSearchTerm(); - this.updateResults(); + if (this.prefillNextSearchTerm()) { + this.updateResults(); + } } this.positionDropdown(); } else {