Skip to content

Commit 7c2c5a8

Browse files
committed
fix(select2): preserve placeholder and prevent dummy item on multiple
Tweaked Select2 init so that single selects correctly show the placeholder without auto-selecting the first item, and multiple selects no longer insert a dummy empty option when all items are removed.
1 parent ace718c commit 7c2c5a8

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

js/admin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,12 @@
835835
config = { width: "100%" },
836836
ph = $that.data("placeholder") || $that.attr("placeholder");
837837

838-
if (ph?.length && !$that.prop('multiple')) {
838+
if (ph?.length) {
839839
config.placeholder = ph;
840840
config.allowClear = true;
841841

842-
if (!$that.find('option[value=""]').length) {
843-
$that.prepend('<option></option>');
842+
if (!$that.prop('multiple') && !$that.find('option[value=""]').length) {
843+
$that.prepend('<option value="" disabled selected></option>');
844844
}
845845
}
846846

0 commit comments

Comments
 (0)