Skip to content

Commit

Permalink
Autocomplete attr support (#8083)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Januszewski <[email protected]>
  • Loading branch information
pietaj and Piotr Januszewski authored Sep 7, 2023
1 parent 6eeda89 commit d6bbd49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docs/reference/form_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,18 @@ The available options are:
}
}

``attr``
An array of arbitrary attributes which will be rendered inside the select tag::

$form
->add('category', ModelAutocompleteType::class, [
'property' => 'title',
'attr' => [
'data-my-custom-variable' => 'my-custom-value',
],
])
;

Sonata\\AdminBundle\\Form\\Type\\ChoiceFieldMaskType
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ file that was distributed with this source code.
#}
{% apply spaceless %}
<select id="{{ id }}_autocomplete_input" data-sonata-select2="false"
{%- if read_only|default(false) %} readonly="readonly"{% endif -%}
{%- if disabled %} disabled="disabled"{% endif %}
{%- if multiple %} multiple="multiple"{% endif %}
{%- for attribute, value in attr %} {{ attribute }}="{{ value }}" {% endfor -%}
>
{%- for idx, val in value|filter((val, idx) => idx~'' != '_labels') -%}
<option value="{{ val }}" selected>{{ value['_labels'][idx] }}</option>
Expand Down Expand Up @@ -70,7 +70,6 @@ file that was distributed with this source code.
placeholder: '{{ placeholder ?: allowClearPlaceholder }}', // allowClear needs placeholder to work properly
allowClear: {{ required ? 'false' : 'true' }},
enable: {{ disabled ? 'false' : 'true' }},
readonly: {{ attr.read_only|default(false) ? 'true' : 'false' }},
minimumInputLength: {{ minimum_input_length }},
theme: 'bootstrap',
width: function() {
Expand Down

0 comments on commit d6bbd49

Please sign in to comment.