1
0
mirror of synced 2025-02-16 20:13:16 +03:00

Fix select2('') calls on multiple elements

This fixes an issue when any of Select2's special options are called on
multiple elements, it would only affect the first option in the group.
This was because Select2 was only applying any changes to the first
element in the group (as chosen by jQuery) instead of applying changes
on each and every element within the list.

This has the new side effect of special options like `select2('data')`
returning the results for the last element in the list instead of the
first element. Because the previous functionality was considered
unspecified behaviour, this is not being treated as a breaking change.

This closes https://github.com/select2/select2/issues/3413
This closes https://github.com/select2/select2/pull/3495
This commit is contained in:
Quentin Pradet 2015-11-09 19:02:59 -05:00 committed by Kevin Brown
parent 7c47912b73
commit 878bb3ab07

View File

@ -24,18 +24,22 @@ define([
return this;
} else if (typeof options === 'string') {
var instance = this.data('select2');
var ret;
if (instance == null && window.console && console.error) {
console.error(
'The select2(\'' + options + '\') method was called on an ' +
'element that is not using Select2.'
);
}
this.each(function () {
var instance = $(this).data('select2');
var args = Array.prototype.slice.call(arguments, 1);
if (instance == null && window.console && console.error) {
console.error(
'The select2(\'' + options + '\') method was called on an ' +
'element that is not using Select2.'
);
}
var ret = instance[options].apply(instance, args);
var args = Array.prototype.slice.call(arguments, 1);
ret = instance[options].apply(instance, args);
});
// Check if we should be returning `this`
if ($.inArray(options, thisMethods) > -1) {