django-crispy-forms / crispy-tailwind

A Tailwind template pack for django-crispy-forms
MIT License
329 stars 56 forks source link

select_option.html inherits parent attributes #132

Closed nikolaysm closed 4 months ago

nikolaysm commented 1 year ago

There is an option to enable and disable parent attributes for options at ChoiceWidget:

image

https://github.com/django/django/blob/5b3d3e400ab9334ba429ca360c9818c6dfc3a51b/django/forms/widgets.py#L585

So select_option.html doesn't take this into account.

One of the solutions is to use field.field.widget.option_inherits_attrs:

<option value="{{ value|stringformat:'s' }}"{% if field.field.widget.option_inherits_attrs %} {{ field.field.widget.attrs|flatatt }}{% endif %}{% if field.value|stringformat:'s' == value|stringformat:'s' %} selected{% endif %}>{{ label }}</option>

hongquan commented 11 months ago

PR to fix has been made: https://github.com/django-crispy-forms/crispy-tailwind/pull/133