django-crispy-forms / crispy-tailwind

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

[bug] checkboxmultipleselect is a radio #126

Open rosscdh opened 1 year ago

rosscdh commented 1 year ago

as per https://github.com/django/django/blob/main/django/forms/widgets.py#L839

unfortunately the widget inherits from radioselect which means that isinstance will return true an show a radio select due to the order in https://github.com/django-crispy-forms/crispy-tailwind/blob/main/crispy_tailwind/templates/tailwind/field.html#L20

as is demonstrated here

(Pdb) isinstance(form.fields.get('infrastructure').widget, forms.CheckboxSelectMultiple)
True
(Pdb) isinstance(form.fields.get('infrastructure').widget, forms.RadioSelect)
True

a working fix would be to test for the class name rather?

 form.fields.get('infrastructure').widget.__class__.__name__
'CheckboxSelectMultiple'
dpjanes commented 7 months ago

Seconded on this one:

This is how django-crispy-forms handles it:

https://github.com/django-crispy-forms/django-crispy-forms/blob/main/crispy_forms/templatetags/crispy_forms_field.py

    return isinstance(field.field.widget, forms.RadioSelect) and not isinstance(
        field.field.widget, forms.CheckboxSelectMultiple
    )
GitRon commented 6 months ago

Hi @rosscdh!

Nice to meet you here! 😄

What do you say about @dpjanes suggestion how crispy forms core handles this?

Best
Ronny