Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown Empty #108

Open
Greg83480 opened this issue Sep 6, 2021 · 2 comments
Open

Dropdown Empty #108

Greg83480 opened this issue Sep 6, 2021 · 2 comments

Comments

@Greg83480
Copy link

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
Copy link

Josde commented Jul 27, 2022

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
Copy link
Contributor

GitRon commented Feb 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants