django-crispy-forms / crispy-tailwind

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

fixed bug which caused bound forms to lose selected option #89

Open io2 opened 3 years ago

io2 commented 3 years ago

in django forms.ModelForm types, the select > option value attribute is usually set to the primary key of the model object (typically an integer)

This commit converts field.value to string to ensure the if condition for adding selected to the <option> html is satisfied.

smithdc1 commented 3 years ago

Hi @io2

Sorry for taking some time to get to this. There's a few things going on with this at the moment.

The first is that we should probably mirror the logic from checkboxes and radios. There are a few other edge cases we should look to capture. See this line here.

https://github.com/django-crispy-forms/crispy-tailwind/blob/3ad4c94ebf0fab7ef73b2fa970bd0a4b63d0a3f1/crispy_tailwind/templates/tailwind/layout/checkboxselectmultiple.html#L8

Secondly is that this can be improved using the new optgroups filter in django-crispy-forms which will simplify this logic here significantly. See https://github.com/django-crispy-forms/django-crispy-forms/pull/1127

io2 commented 3 years ago

@smithdc1 I'll take a look sometime and push an update.

GitRon commented 6 months ago

Hi @io2!

@smithdc1 I'll take a look sometime and push an update.

Any update on this topic? 🙂

Best
Ronny