Fixed not to break use case: setting the new value after someone was just searching with a different value
https://github.com/ivaynberg/select2/issues/2751
This commit is contained in:
parent
03a15e070b
commit
0cc0ac43f5
@ -814,6 +814,8 @@ 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.lastSearchTerm = 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();
|
||||||
@ -1507,7 +1509,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextSearchTerm = this.opts.nextSearchTerm(this.data(), this.search.val());
|
var nextSearchTerm = this.opts.nextSearchTerm(this.data(), this.lastSearchTerm);
|
||||||
if(nextSearchTerm != undefined){
|
if(nextSearchTerm != undefined){
|
||||||
this.search.val(nextSearchTerm);
|
this.search.val(nextSearchTerm);
|
||||||
this.search.select();
|
this.search.select();
|
||||||
@ -2318,6 +2320,7 @@ 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.lastSearchTerm = self.search.val();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2454,6 +2457,7 @@ 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.lastSearchTerm = this.search.val();
|
||||||
this.close();
|
this.close();
|
||||||
|
|
||||||
if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
|
if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
|
||||||
@ -2988,6 +2992,9 @@ 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.lastSearchTerm = this.search.val();
|
||||||
|
|
||||||
this.clearSearch();
|
this.clearSearch();
|
||||||
this.updateResults();
|
this.updateResults();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user