Warn when Select2 is called without being initalized
Since Select2 methods should not be called on an element where Select2 has not yet been initialized, this raises an error when it happens. This does not silence the original error, but it does provide the user with some more context about why they are seeing a TypeError. This closes https://github.com/select2/select2/issues/3173.
This commit is contained in:
parent
878de20d44
commit
a993ed9ca9
8
dist/js/select2.full.js
vendored
8
dist/js/select2.full.js
vendored
@ -5627,6 +5627,14 @@ S2.define('jquery.select2',[
|
|||||||
return this;
|
return this;
|
||||||
} else if (typeof options === 'string') {
|
} else if (typeof options === 'string') {
|
||||||
var instance = this.data('select2');
|
var instance = this.data('select2');
|
||||||
|
|
||||||
|
if (instance == null && window.console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'The select2(\'' + options + '\') method was called on an ' +
|
||||||
|
'element that is not using Select2.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
|
||||||
var ret = instance[options](args);
|
var ret = instance[options](args);
|
||||||
|
2
dist/js/select2.full.min.js
vendored
2
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
8
dist/js/select2.js
vendored
8
dist/js/select2.js
vendored
@ -5289,6 +5289,14 @@ S2.define('jquery.select2',[
|
|||||||
return this;
|
return this;
|
||||||
} else if (typeof options === 'string') {
|
} else if (typeof options === 'string') {
|
||||||
var instance = this.data('select2');
|
var instance = this.data('select2');
|
||||||
|
|
||||||
|
if (instance == null && window.console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'The select2(\'' + options + '\') method was called on an ' +
|
||||||
|
'element that is not using Select2.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
|
||||||
var ret = instance[options](args);
|
var ret = instance[options](args);
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
@ -25,6 +25,14 @@ define([
|
|||||||
return this;
|
return this;
|
||||||
} else if (typeof options === 'string') {
|
} else if (typeof options === 'string') {
|
||||||
var instance = this.data('select2');
|
var instance = this.data('select2');
|
||||||
|
|
||||||
|
if (instance == null && window.console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'The select2(\'' + options + '\') method was called on an ' +
|
||||||
|
'element that is not using Select2.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
|
||||||
var ret = instance[options](args);
|
var ret = instance[options](args);
|
||||||
|
Loading…
Reference in New Issue
Block a user