After clearSearch nextSearchTerm is not cleared
https://github.com/ivaynberg/select2/issues/2753
This commit is contained in:
parent
5a184921b6
commit
03a15e070b
51
select2.js
51
select2.js
@ -814,8 +814,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// focusin can cause focus wars between modals and select2 since the dropdown is outside the modal.
|
// focusin can cause focus wars between modals and select2 since the dropdown is outside the modal.
|
||||||
this.dropdown.on("click mouseup mousedown touchstart touchend focusin", function (e) { e.stopPropagation(); });
|
this.dropdown.on("click mouseup mousedown touchstart touchend focusin", function (e) { e.stopPropagation(); });
|
||||||
|
|
||||||
this.nextSearchTerm = undefined;
|
|
||||||
|
|
||||||
if ($.isFunction(this.opts.initSelection)) {
|
if ($.isFunction(this.opts.initSelection)) {
|
||||||
// initialize selection based on the current value of the source element
|
// initialize selection based on the current value of the source element
|
||||||
this.initSelection();
|
this.initSelection();
|
||||||
@ -1499,6 +1497,23 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
var nextSearchTerm = this.opts.nextSearchTerm(this.data(), this.search.val());
|
||||||
|
if(nextSearchTerm != undefined){
|
||||||
|
this.search.val(nextSearchTerm);
|
||||||
|
this.search.select();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
//abstract
|
//abstract
|
||||||
getMaximumSelectionSize: function() {
|
getMaximumSelectionSize: function() {
|
||||||
return evaluate(this.opts.maximumSelectionSize, this.opts.element);
|
return evaluate(this.opts.maximumSelectionSize, this.opts.element);
|
||||||
@ -2015,14 +2030,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initializes search's value with nextSearchTerm (if defined by user)
|
this.prefillNextSearchTerm();
|
||||||
// ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
|
|
||||||
if(this.search.val() === "") {
|
|
||||||
if(this.nextSearchTerm != undefined){
|
|
||||||
this.search.val(this.nextSearchTerm);
|
|
||||||
this.search.select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.focusser.prop("disabled", true).val("");
|
this.focusser.prop("disabled", true).val("");
|
||||||
this.updateResults(true);
|
this.updateResults(true);
|
||||||
@ -2310,7 +2318,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
self.updateSelection(selected);
|
self.updateSelection(selected);
|
||||||
self.close();
|
self.close();
|
||||||
self.setPlaceholder();
|
self.setPlaceholder();
|
||||||
self.nextSearchTerm = self.opts.nextSearchTerm(selected, self.search.val());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2447,7 +2454,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
|
this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
|
||||||
|
|
||||||
this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
|
|
||||||
this.close();
|
this.close();
|
||||||
|
|
||||||
if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
|
if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
|
||||||
@ -2914,16 +2920,9 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
this.focusSearch();
|
this.focusSearch();
|
||||||
|
|
||||||
// initializes search's value with nextSearchTerm (if defined by user)
|
this.prefillNextSearchTerm();
|
||||||
// ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
|
|
||||||
if(this.search.val() === "") {
|
|
||||||
if(this.nextSearchTerm != undefined){
|
|
||||||
this.search.val(this.nextSearchTerm);
|
|
||||||
this.search.select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateResults(true);
|
this.updateResults(true);
|
||||||
|
|
||||||
if (this.opts.shouldFocusInput(this)) {
|
if (this.opts.shouldFocusInput(this)) {
|
||||||
this.search.focus();
|
this.search.focus();
|
||||||
}
|
}
|
||||||
@ -2989,9 +2988,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
|
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
|
||||||
|
|
||||||
// keep track of the search's value before it gets cleared
|
|
||||||
this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
|
|
||||||
|
|
||||||
this.clearSearch();
|
this.clearSearch();
|
||||||
this.updateResults();
|
this.updateResults();
|
||||||
|
|
||||||
@ -3010,11 +3006,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.updateResults(true);
|
this.updateResults(true);
|
||||||
} else {
|
} else {
|
||||||
// initializes search's value with nextSearchTerm and update search result
|
// initializes search's value with nextSearchTerm and update search result
|
||||||
if(this.nextSearchTerm != undefined){
|
this.prefillNextSearchTerm();
|
||||||
this.search.val(this.nextSearchTerm);
|
this.updateResults();
|
||||||
this.updateResults();
|
|
||||||
this.search.select();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.positionDropdown();
|
this.positionDropdown();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user