Skip to content

[Autocomplete] Distinct autocomplete field from normal field in templates #581

Closed
@AlexandreGerault

Description

@AlexandreGerault

Hi folks.

I was wondering how to customize choice_widget without impacting the autocomplete field. After a bit of looking I ended up with this solution:

{% block choice_widget %}
    {% set attr = attr|merge({'class': 'mt-1 block w-full rounded-md border-gray-300 py-2 pl-3 pr-10 text-base focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm'}) %}

    {% if attr['data-controller'] is not defined %}
    <select name="{{ full_name }}" {{ block('widget_attributes') }}>
        {% for choice in choices %}
            <option value="{{ choice.value }}" {% if choice.value == value %}selected{% endif %}>{{ choice.label }}</option>
        {% endfor %}
    </select>
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}

It is not ideal for readability to only check the presence of data-controller in attributes, and might be side effects with other inputs defining a data-controller attribute.

I'd rather expect a is_autocomplete variable instead. We were discussing about this with @weaverryan on the Slack. Before opening a PR, it might be better to discuss the pros/cons in an issue 😄

What's your point about this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions