1
0
mirror of synced 2025-02-04 06:09:23 +03:00

selectOnClose now properly works with closeOnSelect

Previously we hacked around the infinite loop between closeOnSelect and
selectOnClose by attempting to detect what event was being triggered
without knowing what event triggered it. Now we properly relay the
Select2 event and the jQuery event that triggered the select or unselect

This closes https://github.com/select2/select2/issues/4012
This commit is contained in:
Kevin Brown 2016-05-14 22:04:29 -04:00
parent ad8447cc35
commit 481c43883e
2 changed files with 17 additions and 4 deletions

View File

@ -25,7 +25,10 @@ define([
return; return;
} }
this.trigger('close', {}); this.trigger('close', {
originalEvent: originalEvent,
originalSelect2Event: evt
});
}; };
return CloseOnSelect; return CloseOnSelect;

View File

@ -8,12 +8,22 @@ define([
decorated.call(this, container, $container); decorated.call(this, container, $container);
container.on('close', function () { container.on('close', function (params) {
self._handleSelectOnClose(); self._handleSelectOnClose(params);
}); });
}; };
SelectOnClose.prototype._handleSelectOnClose = function () { SelectOnClose.prototype._handleSelectOnClose = function (_, params) {
if (params && params.originalSelect2Event != null) {
var event = params.originalSelect2Event;
// Don't select an item if the close event was triggered from a select or
// unselect event
if (event._type === 'select' || event._type === 'unselect') {
return;
}
}
var $highlightedResults = this.getHighlightedResults(); var $highlightedResults = this.getHighlightedResults();
// Only select highlighted results // Only select highlighted results