Closed nikolaysm closed 4 months ago
There is an option to enable and disable parent attributes for options at ChoiceWidget:
ChoiceWidget
https://github.com/django/django/blob/5b3d3e400ab9334ba429ca360c9818c6dfc3a51b/django/forms/widgets.py#L585
So select_option.html doesn't take this into account.
select_option.html
One of the solutions is to use field.field.widget.option_inherits_attrs:
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>
<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>
PR to fix has been made: https://github.com/django-crispy-forms/crispy-tailwind/pull/133
There is an option to enable and disable parent attributes for options at
ChoiceWidget
: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>