Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Empty Dropdown Using ModelSelect2Widget #3

Closed
celine-setyawan opened this issue Jul 10, 2020 · 1 comment
Closed

Empty Dropdown Using ModelSelect2Widget #3

celine-setyawan opened this issue Jul 10, 2020 · 1 comment

Comments

@celine-setyawan
Copy link

Hello, thank you for the opensource, this is my first time using django-select2.

I don't know why my dropdown won't show anything. This is the frontend. I want those 4 fields chained. But they dont even show any data.
image'

Seems like I have similar problem like this issue. I've tried the solution but it doesn't work for me. If I remove the widgets=ModelSelect2Widget, my dropdown is populated with data from the DB, so I guess the problem lies with the ModelSelect2Widget. I use django-select2==7.4.2 and django==3.0.7

This is my forms.py

class FormSekolah(ModelForm):
          provinsi = ModelChoiceField(
                          queryset=Provinsi.objects.all(),
                          widget=ModelSelect2Widget(
                                              attrs={
                                                       'class': 'form-control form-control-sm',
                                                       'data-placeholder': '-- Pilih Provinsi --',
                                                       'data-minimum-input-length': 0
                                                },
                           model=Provinsi,
                           search_fields=['nama__icontains'],
                           dependent_fields={'kokab': 'cities'}
                           )
         )

        class Meta:
                  model = Sekolah
                  fields = [
                              # other field,
                              'provinsi',
                   ]

This is my models.py

class Provinsi(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    nama = models.CharField(max_length=50)
    negara = models.ForeignKey(Negara, on_delete=models.CASCADE, related_name="provinces")

    def __str__(self):
        return self.nama

Do I need to do something with my views.py (beside create and save forms and render to the html) or even create my own .js ?

Thanks before.

@tow3r91
Copy link

tow3r91 commented Mar 13, 2021

I have the same problem. Some answer???

Repository owner locked and limited conversation to collaborators Mar 13, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants