Skip to content
Snippets Groups Projects

Use placeholder if nothing selected.

1 file
+ 38
20
Compare changes
  • Side-by-side
  • Inline
+ 38
20
(function ($, Drupal, drupalSettings) {
Drupal.behaviors.select2MultiCheckboxes = {
attach: function (context) {
$(".select2-multiple").select2MultiCheckboxes({
templateSelection: function (selected, total, context) {
return Drupal.t("Selected @selected of @total", {
"@selected": selected.length,
"@total": total
});
},
$(".select2-multiple").each(function () {
let $item = $(this);
$item.select2MultiCheckboxes({
templateSelection: function (selected, total, context) {
if (selected.length === 0) {
return $item.data('select2Config').placeholder;
}
else {
return Drupal.t("Selected @selected of @total", {
"@selected": selected.length,
"@total": total
});
}
}
});
// placeholder: this.attr('placeholder'),
});
$(".select2-single").select2MultiCheckboxes({
templateSelection: function (selected, total, context) {
if (typeof (selected) == "object") {
return Drupal.t("Selected @selected of @total", {
"@selected": selected.length,
"@total": total - 1
});
} else {
return Drupal.t("Selected @selected of @total", {
"@selected": 1,
"@total": total - 1
});
$(".select2-single").each(function () {
let $item = $(this);
$item.select2MultiCheckboxes({
templateSelection: function (selected, total, context) {
if (typeof (selected) == "object") {
if (selected.length === 0) {
return $item.data('select2Config').placeholder;
}
else {
return Drupal.t("Selected @selected of @total", {
"@selected": selected.length,
"@total": total - 1
});
}
}
else {
return Drupal.t("Selected @selected of @total", {
"@selected": 1,
"@total": total - 1
});
}
}
},
});
});
// Get the widget width for elements with multiple selections.
$(".select2-multiple + .select2-container").each(function(index){
Loading