Skip to content

s2forms.Select2Widget no results in template #208

@fxlxx

Description

@fxlxx

Goal
Don't use a Django Model but a SQL query or dummy data

Problem
No results are shown in template, it's just an empty dropdown menu

Code Snippet

from django import forms
from django_select2 import forms as s2forms

class UserWidget(s2forms.Select2Widget):

    def build_attrs(self, *args, **kwargs):
        attrs = super().build_attrs(*args, **kwargs)

        # some dummy data which will be replaced by an sql query
        data = [
            {'id': '1', 'text': 'Example1'},
            {'id': '2', 'text': 'Example2'},
            {'id': '3', 'text': 'Example3'},
            {'id': '4', 'text': 'Example4'},
        ]
        attrs['data'] = data

        return attrs



class UserForm(forms.Form):
    user = forms.ChoiceField(widget=UserWidget)

What am i missing? A ModelSelect2Widget works fine, so the probem should be in my forms.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions