django-crispy-forms / crispy-tailwind

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

Dropdown Empty #108

Open Greg83480 opened 2 years ago

Greg83480 commented 2 years ago

Hello,

I'am using this form class to populate an dropdown list. My problem the dropdown is empty

class LeadModelForm(forms.ModelForm): class Meta: model = InstaProfile fields = fields = 'all' choices = Category.objects.all().values_list('name','name') choice_list = []

    for item in choices:
        choice_list.append(item)

    widgets ={

        'category': forms.Select(choices=choice_list,attrs={'class': 'form-select'}),

    }

If a i remove the crispy filter on my html template file is working

Any idea ?

Thank you

Greg

Josde commented 1 year ago

Had the same issue, setting the choices list on the ChoiceField rather than on the Select widget solved the issue for me (though I cannot figure how to apply style to the created widget)

So your code would look something like this: category = forms.ChoiceField(choices=choice_list, widget=forms.Select(attrs={'class': 'form-select'}))

Hope this helps!

GitRon commented 5 months ago

@Greg83480 Is your issue solved? Been a while since this ticket was created 😅