Closed
Description
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?