Skip to content

Commit 78c301f

Browse files
committed
Added debug option
Now most of the warning messages will only be displayed if the `debug` option is set when initializing Select2. This closes select2#3100.
1 parent 7feb90f commit 78c301f

14 files changed

Lines changed: 66 additions & 56 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ define('select2/selection/allowClear',[
11711171
decorated.call(this, container, $container);
11721172

11731173
if (self.placeholder == null) {
1174-
if (window.console && console.error) {
1174+
if (self.options.get('debug') && window.console && console.error) {
11751175
console.error(
11761176
'Select2: The `allowClear` option should be used in combination ' +
11771177
'with the `placeholder` option.'
@@ -2782,7 +2782,7 @@ define('select2/data/ajax',[
27822782
var $request = options.transport(options, function (data) {
27832783
var results = self.processResults(data, params);
27842784

2785-
if (window.console && console.error) {
2785+
if (self.options.get('debug') && window.console && console.error) {
27862786
// Check to make sure that the response included a `results` key.
27872787
if (!results || !results.results || !$.isArray(results.results)) {
27882788
console.error(
@@ -3963,7 +3963,7 @@ define('select2/defaults',[
39633963
// The translation could not be loaded at all. Sometimes this is
39643964
// because of a configuration problem, other times this can be
39653965
// because of how Select2 helps load all possible translation files.
3966-
if (window.console && console.warn) {
3966+
if (options.debug && window.console && console.warn) {
39673967
console.warn(
39683968
'Select2: The language file for "' + name + '" could not be ' +
39693969
'automatically loaded. A fallback will be used instead.'
@@ -4044,6 +4044,7 @@ define('select2/defaults',[
40444044
amdBase: 'select2/',
40454045
amdLanguageBase: 'select2/i18n/',
40464046
closeOnSelect: true,
4047+
debug: false,
40474048
escapeMarkup: Utils.escapeMarkup,
40484049
language: EnglishTranslation,
40494050
matcher: matcher,
@@ -4139,7 +4140,7 @@ define('select2/options',[
41394140
$e.prop('multiple', this.options.multiple);
41404141

41414142
if ($e.data('select2Tags')) {
4142-
if (window.console && console.warn) {
4143+
if (this.options.debug && window.console && console.warn) {
41434144
console.warn(
41444145
'Select2: The `data-select2-tags` attribute has been changed to ' +
41454146
'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4152,7 +4153,7 @@ define('select2/options',[
41524153
}
41534154

41544155
if ($e.data('ajaxUrl')) {
4155-
if (window.console && console.warn) {
4156+
if (this.options.debug && window.console && console.warn) {
41564157
console.warn(
41574158
'Select2: The `data-ajax-url` attribute has been changed to ' +
41584159
'`data-ajax--url` and support for the old attribute will be removed' +
@@ -4617,7 +4618,7 @@ define('select2/core',[
46174618
};
46184619

46194620
Select2.prototype.enable = function (args) {
4620-
if (window.console && console.warn) {
4621+
if (this.options.get('debug') && window.console && console.warn) {
46214622
console.warn(
46224623
'Select2: The `select2("enable")` method has been deprecated and will' +
46234624
' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -4635,7 +4636,8 @@ define('select2/core',[
46354636
};
46364637

46374638
Select2.prototype.data = function () {
4638-
if (arguments.length > 0 && window.console && console.warn) {
4639+
if (this.options.get('debug') &&
4640+
arguments.length > 0 && window.console && console.warn) {
46394641
console.warn(
46404642
'Select2: Data can no longer be set using `select2("data")`. You ' +
46414643
'should consider setting the value instead using `$element.val()`.'
@@ -4652,7 +4654,7 @@ define('select2/core',[
46524654
};
46534655

46544656
Select2.prototype.val = function (args) {
4655-
if (window.console && console.warn) {
4657+
if (this.options.get('debug') && window.console && console.warn) {
46564658
console.warn(
46574659
'Select2: The `select2("val")` method has been deprecated and will be' +
46584660
' removed in later Select2 versions. Use $element.val() instead.'
@@ -4999,7 +5001,7 @@ define('select2/compat/initSelection',[
49995001
'jquery'
50005002
], function ($) {
50015003
function InitSelection (decorated, $element, options) {
5002-
if (window.console && console.warn) {
5004+
if (options.get('debug') && window.console && console.warn) {
50035005
console.warn(
50045006
'Select2: The `initSelection` option has been deprecated in favor' +
50055007
' of a custom data adapter that overrides the `current` method. ' +
@@ -5046,7 +5048,7 @@ define('select2/compat/inputData',[
50465048
this._valueSeparator = options.get('valueSeparator') || ',';
50475049

50485050
if ($element.prop('type') === 'hidden') {
5049-
if (console && console.warn) {
5051+
if (options.get('debug') && console && console.warn) {
50505052
console.warn(
50515053
'Select2: Using a hidden input with Select2 is no longer ' +
50525054
'supported and may stop working in the future. It is recommended ' +
@@ -5170,7 +5172,7 @@ define('select2/compat/query',[
51705172

51715173
], function () {
51725174
function Query (decorated, $element, options) {
5173-
if (window.console && console.warn) {
5175+
if (options.get('debug') && window.console && console.warn) {
51745176
console.warn(
51755177
'Select2: The `query` option has been deprecated in favor of a ' +
51765178
'custom data adapter that overrides the `query` method. Support ' +

dist/js/select2.amd.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ define('select2/selection/allowClear',[
11711171
decorated.call(this, container, $container);
11721172

11731173
if (self.placeholder == null) {
1174-
if (window.console && console.error) {
1174+
if (self.options.get('debug') && window.console && console.error) {
11751175
console.error(
11761176
'Select2: The `allowClear` option should be used in combination ' +
11771177
'with the `placeholder` option.'
@@ -2782,7 +2782,7 @@ define('select2/data/ajax',[
27822782
var $request = options.transport(options, function (data) {
27832783
var results = self.processResults(data, params);
27842784

2785-
if (window.console && console.error) {
2785+
if (self.options.get('debug') && window.console && console.error) {
27862786
// Check to make sure that the response included a `results` key.
27872787
if (!results || !results.results || !$.isArray(results.results)) {
27882788
console.error(
@@ -3963,7 +3963,7 @@ define('select2/defaults',[
39633963
// The translation could not be loaded at all. Sometimes this is
39643964
// because of a configuration problem, other times this can be
39653965
// because of how Select2 helps load all possible translation files.
3966-
if (window.console && console.warn) {
3966+
if (options.debug && window.console && console.warn) {
39673967
console.warn(
39683968
'Select2: The language file for "' + name + '" could not be ' +
39693969
'automatically loaded. A fallback will be used instead.'
@@ -4044,6 +4044,7 @@ define('select2/defaults',[
40444044
amdBase: 'select2/',
40454045
amdLanguageBase: 'select2/i18n/',
40464046
closeOnSelect: true,
4047+
debug: false,
40474048
escapeMarkup: Utils.escapeMarkup,
40484049
language: EnglishTranslation,
40494050
matcher: matcher,
@@ -4139,7 +4140,7 @@ define('select2/options',[
41394140
$e.prop('multiple', this.options.multiple);
41404141

41414142
if ($e.data('select2Tags')) {
4142-
if (window.console && console.warn) {
4143+
if (this.options.debug && window.console && console.warn) {
41434144
console.warn(
41444145
'Select2: The `data-select2-tags` attribute has been changed to ' +
41454146
'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4152,7 +4153,7 @@ define('select2/options',[
41524153
}
41534154

41544155
if ($e.data('ajaxUrl')) {
4155-
if (window.console && console.warn) {
4156+
if (this.options.debug && window.console && console.warn) {
41564157
console.warn(
41574158
'Select2: The `data-ajax-url` attribute has been changed to ' +
41584159
'`data-ajax--url` and support for the old attribute will be removed' +
@@ -4617,7 +4618,7 @@ define('select2/core',[
46174618
};
46184619

46194620
Select2.prototype.enable = function (args) {
4620-
if (window.console && console.warn) {
4621+
if (this.options.get('debug') && window.console && console.warn) {
46214622
console.warn(
46224623
'Select2: The `select2("enable")` method has been deprecated and will' +
46234624
' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -4635,7 +4636,8 @@ define('select2/core',[
46354636
};
46364637

46374638
Select2.prototype.data = function () {
4638-
if (arguments.length > 0 && window.console && console.warn) {
4639+
if (this.options.get('debug') &&
4640+
arguments.length > 0 && window.console && console.warn) {
46394641
console.warn(
46404642
'Select2: Data can no longer be set using `select2("data")`. You ' +
46414643
'should consider setting the value instead using `$element.val()`.'
@@ -4652,7 +4654,7 @@ define('select2/core',[
46524654
};
46534655

46544656
Select2.prototype.val = function (args) {
4655-
if (window.console && console.warn) {
4657+
if (this.options.get('debug') && window.console && console.warn) {
46564658
console.warn(
46574659
'Select2: The `select2("val")` method has been deprecated and will be' +
46584660
' removed in later Select2 versions. Use $element.val() instead.'

dist/js/select2.full.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:26:05 GMT
2+
* Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:39:48 GMT
33
* https://select2.github.io
44
*
55
* Released under the MIT license
@@ -1617,7 +1617,7 @@ define('select2/selection/allowClear',[
16171617
decorated.call(this, container, $container);
16181618

16191619
if (self.placeholder == null) {
1620-
if (window.console && console.error) {
1620+
if (self.options.get('debug') && window.console && console.error) {
16211621
console.error(
16221622
'Select2: The `allowClear` option should be used in combination ' +
16231623
'with the `placeholder` option.'
@@ -3228,7 +3228,7 @@ define('select2/data/ajax',[
32283228
var $request = options.transport(options, function (data) {
32293229
var results = self.processResults(data, params);
32303230

3231-
if (window.console && console.error) {
3231+
if (self.options.get('debug') && window.console && console.error) {
32323232
// Check to make sure that the response included a `results` key.
32333233
if (!results || !results.results || !$.isArray(results.results)) {
32343234
console.error(
@@ -4409,7 +4409,7 @@ define('select2/defaults',[
44094409
// The translation could not be loaded at all. Sometimes this is
44104410
// because of a configuration problem, other times this can be
44114411
// because of how Select2 helps load all possible translation files.
4412-
if (window.console && console.warn) {
4412+
if (options.debug && window.console && console.warn) {
44134413
console.warn(
44144414
'Select2: The language file for "' + name + '" could not be ' +
44154415
'automatically loaded. A fallback will be used instead.'
@@ -4490,6 +4490,7 @@ define('select2/defaults',[
44904490
amdBase: 'select2/',
44914491
amdLanguageBase: 'select2/i18n/',
44924492
closeOnSelect: true,
4493+
debug: false,
44934494
escapeMarkup: Utils.escapeMarkup,
44944495
language: EnglishTranslation,
44954496
matcher: matcher,
@@ -4585,7 +4586,7 @@ define('select2/options',[
45854586
$e.prop('multiple', this.options.multiple);
45864587

45874588
if ($e.data('select2Tags')) {
4588-
if (window.console && console.warn) {
4589+
if (this.options.debug && window.console && console.warn) {
45894590
console.warn(
45904591
'Select2: The `data-select2-tags` attribute has been changed to ' +
45914592
'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4598,7 +4599,7 @@ define('select2/options',[
45984599
}
45994600

46004601
if ($e.data('ajaxUrl')) {
4601-
if (window.console && console.warn) {
4602+
if (this.options.debug && window.console && console.warn) {
46024603
console.warn(
46034604
'Select2: The `data-ajax-url` attribute has been changed to ' +
46044605
'`data-ajax--url` and support for the old attribute will be removed' +
@@ -5063,7 +5064,7 @@ define('select2/core',[
50635064
};
50645065

50655066
Select2.prototype.enable = function (args) {
5066-
if (window.console && console.warn) {
5067+
if (this.options.get('debug') && window.console && console.warn) {
50675068
console.warn(
50685069
'Select2: The `select2("enable")` method has been deprecated and will' +
50695070
' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -5081,7 +5082,8 @@ define('select2/core',[
50815082
};
50825083

50835084
Select2.prototype.data = function () {
5084-
if (arguments.length > 0 && window.console && console.warn) {
5085+
if (this.options.get('debug') &&
5086+
arguments.length > 0 && window.console && console.warn) {
50855087
console.warn(
50865088
'Select2: Data can no longer be set using `select2("data")`. You ' +
50875089
'should consider setting the value instead using `$element.val()`.'
@@ -5098,7 +5100,7 @@ define('select2/core',[
50985100
};
50995101

51005102
Select2.prototype.val = function (args) {
5101-
if (window.console && console.warn) {
5103+
if (this.options.get('debug') && window.console && console.warn) {
51025104
console.warn(
51035105
'Select2: The `select2("val")` method has been deprecated and will be' +
51045106
' removed in later Select2 versions. Use $element.val() instead.'
@@ -5445,7 +5447,7 @@ define('select2/compat/initSelection',[
54455447
'jquery'
54465448
], function ($) {
54475449
function InitSelection (decorated, $element, options) {
5448-
if (window.console && console.warn) {
5450+
if (options.get('debug') && window.console && console.warn) {
54495451
console.warn(
54505452
'Select2: The `initSelection` option has been deprecated in favor' +
54515453
' of a custom data adapter that overrides the `current` method. ' +
@@ -5492,7 +5494,7 @@ define('select2/compat/inputData',[
54925494
this._valueSeparator = options.get('valueSeparator') || ',';
54935495

54945496
if ($element.prop('type') === 'hidden') {
5495-
if (console && console.warn) {
5497+
if (options.get('debug') && console && console.warn) {
54965498
console.warn(
54975499
'Select2: Using a hidden input with Select2 is no longer ' +
54985500
'supported and may stop working in the future. It is recommended ' +
@@ -5616,7 +5618,7 @@ define('select2/compat/query',[
56165618

56175619
], function () {
56185620
function Query (decorated, $element, options) {
5619-
if (window.console && console.warn) {
5621+
if (options.get('debug') && window.console && console.warn) {
56205622
console.warn(
56215623
'Select2: The `query` option has been deprecated in favor of a ' +
56225624
'custom data adapter that overrides the `query` method. Support ' +

dist/js/select2.full.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:26:05 GMT
2+
* Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 00:39:48 GMT
33
* https://select2.github.io
44
*
55
* Released under the MIT license
@@ -1617,7 +1617,7 @@ define('select2/selection/allowClear',[
16171617
decorated.call(this, container, $container);
16181618

16191619
if (self.placeholder == null) {
1620-
if (window.console && console.error) {
1620+
if (self.options.get('debug') && window.console && console.error) {
16211621
console.error(
16221622
'Select2: The `allowClear` option should be used in combination ' +
16231623
'with the `placeholder` option.'
@@ -3228,7 +3228,7 @@ define('select2/data/ajax',[
32283228
var $request = options.transport(options, function (data) {
32293229
var results = self.processResults(data, params);
32303230

3231-
if (window.console && console.error) {
3231+
if (self.options.get('debug') && window.console && console.error) {
32323232
// Check to make sure that the response included a `results` key.
32333233
if (!results || !results.results || !$.isArray(results.results)) {
32343234
console.error(
@@ -4409,7 +4409,7 @@ define('select2/defaults',[
44094409
// The translation could not be loaded at all. Sometimes this is
44104410
// because of a configuration problem, other times this can be
44114411
// because of how Select2 helps load all possible translation files.
4412-
if (window.console && console.warn) {
4412+
if (options.debug && window.console && console.warn) {
44134413
console.warn(
44144414
'Select2: The language file for "' + name + '" could not be ' +
44154415
'automatically loaded. A fallback will be used instead.'
@@ -4490,6 +4490,7 @@ define('select2/defaults',[
44904490
amdBase: 'select2/',
44914491
amdLanguageBase: 'select2/i18n/',
44924492
closeOnSelect: true,
4493+
debug: false,
44934494
escapeMarkup: Utils.escapeMarkup,
44944495
language: EnglishTranslation,
44954496
matcher: matcher,
@@ -4585,7 +4586,7 @@ define('select2/options',[
45854586
$e.prop('multiple', this.options.multiple);
45864587

45874588
if ($e.data('select2Tags')) {
4588-
if (window.console && console.warn) {
4589+
if (this.options.debug && window.console && console.warn) {
45894590
console.warn(
45904591
'Select2: The `data-select2-tags` attribute has been changed to ' +
45914592
'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4598,7 +4599,7 @@ define('select2/options',[
45984599
}
45994600

46004601
if ($e.data('ajaxUrl')) {
4601-
if (window.console && console.warn) {
4602+
if (this.options.debug && window.console && console.warn) {
46024603
console.warn(
46034604
'Select2: The `data-ajax-url` attribute has been changed to ' +
46044605
'`data-ajax--url` and support for the old attribute will be removed' +
@@ -5063,7 +5064,7 @@ define('select2/core',[
50635064
};
50645065

50655066
Select2.prototype.enable = function (args) {
5066-
if (window.console && console.warn) {
5067+
if (this.options.get('debug') && window.console && console.warn) {
50675068
console.warn(
50685069
'Select2: The `select2("enable")` method has been deprecated and will' +
50695070
' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -5081,7 +5082,8 @@ define('select2/core',[
50815082
};
50825083

50835084
Select2.prototype.data = function () {
5084-
if (arguments.length > 0 && window.console && console.warn) {
5085+
if (this.options.get('debug') &&
5086+
arguments.length > 0 && window.console && console.warn) {
50855087
console.warn(
50865088
'Select2: Data can no longer be set using `select2("data")`. You ' +
50875089
'should consider setting the value instead using `$element.val()`.'
@@ -5098,7 +5100,7 @@ define('select2/core',[
50985100
};
50995101

51005102
Select2.prototype.val = function (args) {
5101-
if (window.console && console.warn) {
5103+
if (this.options.get('debug') && window.console && console.warn) {
51025104
console.warn(
51035105
'Select2: The `select2("val")` method has been deprecated and will be' +
51045106
' removed in later Select2 versions. Use $element.val() instead.'

dist/js/select2.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)