Ignore old queries, remove highlight when beginning a new query.
This commit is contained in:
parent
76f9bae39a
commit
1eb461a42c
23
select2.js
23
select2.js
@ -687,6 +687,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.results = results = this.container.find(resultsSelector);
|
this.results = results = this.container.find(resultsSelector);
|
||||||
this.search = search = this.container.find("input.select2-input");
|
this.search = search = this.container.find("input.select2-input");
|
||||||
|
|
||||||
|
this.queryCount = 0;
|
||||||
this.resultsPage = 0;
|
this.resultsPage = 0;
|
||||||
this.context = null;
|
this.context = null;
|
||||||
|
|
||||||
@ -1412,7 +1413,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
if (index >= choices.length) index = choices.length - 1;
|
if (index >= choices.length) index = choices.length - 1;
|
||||||
if (index < 0) index = 0;
|
if (index < 0) index = 0;
|
||||||
|
|
||||||
this.results.find(".select2-highlighted").removeClass("select2-highlighted");
|
this.removeHighlight();
|
||||||
|
|
||||||
choice = $(choices[index]);
|
choice = $(choices[index]);
|
||||||
choice.addClass("select2-highlighted");
|
choice.addClass("select2-highlighted");
|
||||||
@ -1425,6 +1426,10 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeHighlight: function() {
|
||||||
|
this.results.find(".select2-highlighted").removeClass("select2-highlighted");
|
||||||
|
},
|
||||||
|
|
||||||
// abstract
|
// abstract
|
||||||
countSelectableResults: function() {
|
countSelectableResults: function() {
|
||||||
return this.findHighlightableChoices().length;
|
return this.findHighlightableChoices().length;
|
||||||
@ -1437,8 +1442,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
var choices = this.findHighlightableChoices();
|
var choices = this.findHighlightableChoices();
|
||||||
this.highlight(choices.index(el));
|
this.highlight(choices.index(el));
|
||||||
} else if (el.length == 0) {
|
} else if (el.length == 0) {
|
||||||
// if we are over an unselectable item remove al highlights
|
// if we are over an unselectable item remove all highlights
|
||||||
this.results.find(".select2-highlighted").removeClass("select2-highlighted");
|
this.removeHighlight();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1505,7 +1510,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
self = this,
|
self = this,
|
||||||
input,
|
input,
|
||||||
term = search.val(),
|
term = search.val(),
|
||||||
lastTerm=$.data(this.container, "select2-last-term");
|
lastTerm = $.data(this.container, "select2-last-term"),
|
||||||
|
queryNumber;
|
||||||
|
|
||||||
// prevent duplicate queries against the same term
|
// prevent duplicate queries against the same term
|
||||||
if (initial !== true && lastTerm && equal(term, lastTerm)) return;
|
if (initial !== true && lastTerm && equal(term, lastTerm)) return;
|
||||||
@ -1527,6 +1533,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
postRender();
|
postRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryNumber = ++this.queryCount;
|
||||||
|
|
||||||
var maxSelSize = this.getMaximumSelectionSize();
|
var maxSelSize = this.getMaximumSelectionSize();
|
||||||
if (maxSelSize >=1) {
|
if (maxSelSize >=1) {
|
||||||
data = this.data();
|
data = this.data();
|
||||||
@ -1561,6 +1569,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
search.addClass("select2-active");
|
search.addClass("select2-active");
|
||||||
|
|
||||||
|
this.removeHighlight();
|
||||||
|
|
||||||
// give the tokenizer a chance to pre-process the input
|
// give the tokenizer a chance to pre-process the input
|
||||||
input = this.tokenize();
|
input = this.tokenize();
|
||||||
if (input != undefined && input != null) {
|
if (input != undefined && input != null) {
|
||||||
@ -1578,6 +1588,11 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
callback: this.bind(function (data) {
|
callback: this.bind(function (data) {
|
||||||
var def; // default choice
|
var def; // default choice
|
||||||
|
|
||||||
|
// ignore old responses
|
||||||
|
if (queryNumber != this.queryCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// ignore a response if the select2 has been closed before it was received
|
// ignore a response if the select2 has been closed before it was received
|
||||||
if (!this.opened()) {
|
if (!this.opened()) {
|
||||||
this.search.removeClass("select2-active");
|
this.search.removeClass("select2-active");
|
||||||
|
Loading…
Reference in New Issue
Block a user