django-crispy-forms / crispy-tailwind

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

In ModelChoiceField 'selected'-Tag is missing, when ModelForm is invalid #98

Closed datenrebell closed 5 months ago

datenrebell commented 3 years ago

Hello,

I have a model with at least two ForeignKey-ModelFields. Both fields are blank = False. I Use a Modelform and Crispy-Tailwind. If the Foreign-Fields in an object are assigned except one and you commit the form, the form will be invalid. The problem is, that in the next rendering of all ForeignFields the "selected"-HTML-tag are missing and so all Foreign-Fields are unselected. The problem does not occur without Crispy-Tailwind.

You can see the problem in my repository: https://github.com/datenrebell/bug_in_crispy_tailwind

I hope you can help me with this Issue. Thanks.

tissieres commented 3 years ago

I have the same problem. It is related to #90 since the default django django/forms/widgets/select.html template is badly overriden by this package. I fixed this by applying the @tailwindcss/forms plugin and overriding the field.html template of this application to remove the inclusion of the custom select.html.