applegrew / django-select2

This is a Django integration for Select2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

7.04 and + dropdown menu not populated initialy

SylvainMartel opened this issue · comments

Describe the bug
I use select2 to populate a dropdown box from the database, then the value selected populate a second dropdown that is dependent on what is selected in the first one.

Up to v7.03 the widget worked fine with this code

merchandise_cat = forms.ModelChoiceField(label='Merchandise Category', queryset=merchandise_category.objects.all().order_by('cat_name'),
                                         widget=ModelSelect2Widget(
                                            model=merchandise_category,
                                            search_fields=['name__icontains'],
                                            ),
                                        required=False)

but with 7.04 and up, the dropdown box is empty and it asks to enter 2 characters. But in previous version, it would show all the items it would find in the database, it's like it's not loading values from the database until you enter chars now

Exception & Traceback

Code Snippet
Please provide us with a code example on how to reproduce the error.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Hi @kinwolfqc thanks for reaching out. If you check out the release notes, you will see, that we fixed a bug in 7.0.4 that previously had the data-minimum-input-length set to 0. This was wrong it should have been set to 2. This is the change you are seeing now. If you want the old behavior back, you can simply overwrite the default to 0:

merchandise_cat = forms.ModelChoiceField(label='Merchandise Category', queryset=merchandise_category.objects.all().order_by('cat_name'),
                                         widget=ModelSelect2Widget(
                                            model=merchandise_category,
                                            search_fields=['name__icontains'],
                                            attrs={'data-minimum-input-length': 0},
                                            ),
                                        required=False)

The attrs={'data-minimum-input-length': 0}, should do the trick.

Let me know if you still have truble to get it working.

Best
-Joe