OK for Tom Select

This commit is contained in:
jf-cbd
2025-11-26 12:03:03 +01:00
parent 02650f8cf7
commit a0f28f725c
3 changed files with 10 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
class TomSelectElement extends HTMLSelectElement {
plugins = [];
connectedCallback() {
if (this.getAttribute('data-tom-select-multiple')) {
if (this.getAttribute('multiple')) {
this.plugins.push('remove_button');
}
@@ -16,7 +16,7 @@ class TomSelectElement extends HTMLSelectElement {
}
};
if (this.getAttribute('data-tom-select-disable-control-input')) {
if (this.getAttribute('data-tom-select-disable-auto-complete')) {
options.controlInput = null;
}
if (this.getAttribute('data-tom-select-max-items-selected')) {

View File

@@ -36,6 +36,8 @@ class ChoiceFormType extends AbstractType
// options to control the inline display of choices
$resolver->setDefault('inline_display', true);
$resolver->setDefined('max_items_selected');
$resolver->setDefault('disable_auto_complete', true);
}
/** @inheritdoc */
@@ -45,6 +47,8 @@ class ChoiceFormType extends AbstractType
// pass options to the view
$view->vars['inline_display'] = $options['inline_display'];
$view->vars['max_items_selected'] = $options['max_items_selected'];
$view->vars['disable_auto_complete'] = $options['disable_auto_complete'];
}
/** @inheritdoc */

View File

@@ -25,10 +25,10 @@
{% set attr = attr|merge({class: (attr.class|default('') ~ ' ibo-input')|trim}) %}
<select is="tom-select-element" class="field_autocomplete ibo-input ibo-input-select ibo-input-select-autocomplete ui-autocomplete-input"
{{ block('widget_attributes') }}
{% if multiple %} multiple="multiple" data-tom-select-multiple="true" {% endif %}
{% if max_items_selected is defined %} data-tom-select-max-items="{{ max_items_selected }}" {% endif %}
{% if placeholder is defined %} data-tom-select-placeholder="{{ placeholder }}" {% endif %}
{% if disable_input is defined%} data-tom-select-disable-control-input=true {% endif %}
{% if multiple %} multiple="multiple" {% endif %}
{% if max_items_selected is defined %} data-tom-select-max-items-selected="{{ max_items_selected }}" {% endif %}
{% if disable_auto_complete %} data-tom-select-disable-auto-complete=true {% endif %}
{% if placeholder is not none %} hidePlaceholder=false {% endif %}
>
{%- if placeholder is not none -%}
<option value=""{% if placeholder_attr|default({}) %}{% with { attr: placeholder_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) }}</option>