Check that allowClear
is used with placeholder
The `allowClear` option may not work as intended if a placeholder is not used. This is becaise the placeholder holds the value that the `<select>` should be reset to when the `x` is hit. An error is now properly raised in the console when Select2 detects that the `allowClear` option is used without the `placeholder` option. This closes https://github.com/select2/select2/issues/3016.
This commit is contained in:
parent
7a8500f198
commit
78b6faf13e
11
dist/js/select2.amd.full.js
vendored
11
dist/js/select2.amd.full.js
vendored
@ -1142,6 +1142,15 @@ define('select2/selection/allowClear',[
|
|||||||
|
|
||||||
decorated.call(this, container, $container);
|
decorated.call(this, container, $container);
|
||||||
|
|
||||||
|
if (self.placeholder == null) {
|
||||||
|
if (console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'Select2: The `allowClear` option should be used in combination ' +
|
||||||
|
'with the `placeholder` option.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.$selection.on('mousedown', '.select2-selection__clear',
|
this.$selection.on('mousedown', '.select2-selection__clear',
|
||||||
function (evt) {
|
function (evt) {
|
||||||
// Ignore the event if it is disabled
|
// Ignore the event if it is disabled
|
||||||
@ -3796,6 +3805,7 @@ define('select2/defaults',[
|
|||||||
options.selectionAdapter,
|
options.selectionAdapter,
|
||||||
Placeholder
|
Placeholder
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.allowClear) {
|
if (options.allowClear) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
@ -3803,7 +3813,6 @@ define('select2/defaults',[
|
|||||||
AllowClear
|
AllowClear
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (options.multiple) {
|
if (options.multiple) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
|
11
dist/js/select2.amd.js
vendored
11
dist/js/select2.amd.js
vendored
@ -1142,6 +1142,15 @@ define('select2/selection/allowClear',[
|
|||||||
|
|
||||||
decorated.call(this, container, $container);
|
decorated.call(this, container, $container);
|
||||||
|
|
||||||
|
if (self.placeholder == null) {
|
||||||
|
if (console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'Select2: The `allowClear` option should be used in combination ' +
|
||||||
|
'with the `placeholder` option.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.$selection.on('mousedown', '.select2-selection__clear',
|
this.$selection.on('mousedown', '.select2-selection__clear',
|
||||||
function (evt) {
|
function (evt) {
|
||||||
// Ignore the event if it is disabled
|
// Ignore the event if it is disabled
|
||||||
@ -3796,6 +3805,7 @@ define('select2/defaults',[
|
|||||||
options.selectionAdapter,
|
options.selectionAdapter,
|
||||||
Placeholder
|
Placeholder
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.allowClear) {
|
if (options.allowClear) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
@ -3803,7 +3813,6 @@ define('select2/defaults',[
|
|||||||
AllowClear
|
AllowClear
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (options.multiple) {
|
if (options.multiple) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
|
11
dist/js/select2.full.js
vendored
11
dist/js/select2.full.js
vendored
@ -1580,6 +1580,15 @@ define('select2/selection/allowClear',[
|
|||||||
|
|
||||||
decorated.call(this, container, $container);
|
decorated.call(this, container, $container);
|
||||||
|
|
||||||
|
if (self.placeholder == null) {
|
||||||
|
if (console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'Select2: The `allowClear` option should be used in combination ' +
|
||||||
|
'with the `placeholder` option.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.$selection.on('mousedown', '.select2-selection__clear',
|
this.$selection.on('mousedown', '.select2-selection__clear',
|
||||||
function (evt) {
|
function (evt) {
|
||||||
// Ignore the event if it is disabled
|
// Ignore the event if it is disabled
|
||||||
@ -4234,6 +4243,7 @@ define('select2/defaults',[
|
|||||||
options.selectionAdapter,
|
options.selectionAdapter,
|
||||||
Placeholder
|
Placeholder
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.allowClear) {
|
if (options.allowClear) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
@ -4241,7 +4251,6 @@ define('select2/defaults',[
|
|||||||
AllowClear
|
AllowClear
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (options.multiple) {
|
if (options.multiple) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
11
dist/js/select2.js
vendored
11
dist/js/select2.js
vendored
@ -1580,6 +1580,15 @@ define('select2/selection/allowClear',[
|
|||||||
|
|
||||||
decorated.call(this, container, $container);
|
decorated.call(this, container, $container);
|
||||||
|
|
||||||
|
if (self.placeholder == null) {
|
||||||
|
if (console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'Select2: The `allowClear` option should be used in combination ' +
|
||||||
|
'with the `placeholder` option.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.$selection.on('mousedown', '.select2-selection__clear',
|
this.$selection.on('mousedown', '.select2-selection__clear',
|
||||||
function (evt) {
|
function (evt) {
|
||||||
// Ignore the event if it is disabled
|
// Ignore the event if it is disabled
|
||||||
@ -4234,6 +4243,7 @@ define('select2/defaults',[
|
|||||||
options.selectionAdapter,
|
options.selectionAdapter,
|
||||||
Placeholder
|
Placeholder
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.allowClear) {
|
if (options.allowClear) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
@ -4241,7 +4251,6 @@ define('select2/defaults',[
|
|||||||
AllowClear
|
AllowClear
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (options.multiple) {
|
if (options.multiple) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
|
4
dist/js/select2.min.js
vendored
4
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
2
src/js/select2/defaults.js
vendored
2
src/js/select2/defaults.js
vendored
@ -172,6 +172,7 @@ define([
|
|||||||
options.selectionAdapter,
|
options.selectionAdapter,
|
||||||
Placeholder
|
Placeholder
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.allowClear) {
|
if (options.allowClear) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
@ -179,7 +180,6 @@ define([
|
|||||||
AllowClear
|
AllowClear
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (options.multiple) {
|
if (options.multiple) {
|
||||||
options.selectionAdapter = Utils.Decorate(
|
options.selectionAdapter = Utils.Decorate(
|
||||||
|
9
src/js/select2/selection/allowClear.js
vendored
9
src/js/select2/selection/allowClear.js
vendored
@ -8,6 +8,15 @@ define([
|
|||||||
|
|
||||||
decorated.call(this, container, $container);
|
decorated.call(this, container, $container);
|
||||||
|
|
||||||
|
if (self.placeholder == null) {
|
||||||
|
if (console && console.error) {
|
||||||
|
console.error(
|
||||||
|
'Select2: The `allowClear` option should be used in combination ' +
|
||||||
|
'with the `placeholder` option.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.$selection.on('mousedown', '.select2-selection__clear',
|
this.$selection.on('mousedown', '.select2-selection__clear',
|
||||||
function (evt) {
|
function (evt) {
|
||||||
// Ignore the event if it is disabled
|
// Ignore the event if it is disabled
|
||||||
|
Loading…
Reference in New Issue
Block a user