You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But currently it also trigger 'close' event when closeOnSelect option is enabled what causes that page is scrolled to that select what is not desirable.
Closing should be triggered only when something is opened or page scrolling should be as option.
I fixed it by changing:
CloseOnSelect.prototype._selectTriggered = function (_, evt) {
var originalEvent = evt.originalEvent;
// Don't close if the control key is being held
if (originalEvent && originalEvent.ctrlKey) {
return;
}
this.trigger('close', {
originalEvent: originalEvent,
originalSelect2Event: evt
});
};
to:
CloseOnSelect.prototype._selectTriggered = function (_, evt) {
var originalEvent = evt.originalEvent;
// Don't close if the control key is being held
if (originalEvent && originalEvent.ctrlKey) {
return;
}
// Don't close something what is already closed
if (!this.$element.data('select2').isOpen()) {
return;
}
this.trigger('close', {
originalEvent: originalEvent,
originalSelect2Event: evt
});
};
The text was updated successfully, but these errors were encountered:
Partly yes... but I suggest to focus not only on site scrolling problem but also on triggering unnecessary event because it can produce some other problems when someone set listener on closing event (close event triggered but nothing was closed, only selected). IMHO.
Ok. Since that issue seems to explain the manifestation of this bug a little better, could you please copy your findings over to that issue? There is another proposed solution there which is somewhat different from yours, so I'd like to see a discussion about the best way to solve this.
I believe that code below should only be responsible for value change:
$("#selectOutsideViewport").select2('trigger', 'select', {data: {id: 123, text: 321}});
But currently it also trigger 'close' event when closeOnSelect option is enabled what causes that page is scrolled to that select what is not desirable.
It can be reproduced here on any browser: https://select2.github.io/examples.html
Slide down to bottom and paste:
$("#id_label_single").select2('trigger', 'select', {data: {id: 123, text: 321}});
Closing should be triggered only when something is opened or page scrolling should be as option.
I fixed it by changing:
to:
The text was updated successfully, but these errors were encountered: