Fix selectOnBlur and closeOnSelect combination
This fixes an infinite loop that used to be caused when both `closeOnSelect` and `selectOnClose` used to be combined, because they both were listening to events triggered by the other one. The problem was that `selectOnClose` was triggering `select` events for data objects which had already been selected. This problem was solved by checking if the data object was already selected before trying to select it again. This closes https://github.com/select2/select2/pull/3751. This closes https://github.com/select2/select2/issues/3169.
This commit is contained in:
parent
d504700c53
commit
393ca4cf7f
2
src/js/select2/core.js
vendored
2
src/js/select2/core.js
vendored
@ -357,7 +357,7 @@ define([
|
||||
'select': 'selecting',
|
||||
'unselect': 'unselecting'
|
||||
};
|
||||
|
||||
|
||||
if (args === undefined) {
|
||||
args = {};
|
||||
}
|
||||
|
13
src/js/select2/dropdown/selectOnClose.js
vendored
13
src/js/select2/dropdown/selectOnClose.js
vendored
@ -16,12 +16,23 @@ define([
|
||||
SelectOnClose.prototype._handleSelectOnClose = function () {
|
||||
var $highlightedResults = this.getHighlightedResults();
|
||||
|
||||
// Only select highlighted results
|
||||
if ($highlightedResults.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = $highlightedResults.data('data');
|
||||
|
||||
// Don't re-select already selected resulte
|
||||
if (
|
||||
(data.element != null && data.element.selected) ||
|
||||
(data.element == null && data.selected)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.trigger('select', {
|
||||
data: $highlightedResults.data('data')
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user