1
0
mirror of synced 2024-11-22 13:06:08 +03:00

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:
Kevin Brown 2015-11-27 17:32:54 -05:00
parent d504700c53
commit 393ca4cf7f
2 changed files with 13 additions and 2 deletions

View File

@ -357,7 +357,7 @@ define([
'select': 'selecting',
'unselect': 'unselecting'
};
if (args === undefined) {
args = {};
}

View File

@ -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
});
};