Skip to content

chained select2, parent required #70

@ghost

Description

Goal
I want to use the chained select2 feature but it does not works fine.

Problem
Taking as example the below code snipped, the city field has to be populated according with country selection. However when country is null then the city is populated with data of all countries. Is it possible to make a child null when parent null?

Code Snippet
class AddressForm(forms.Form):
country = forms.ModelChoiceField(
queryset=Country.objects.all(),
label=u"Country",
widget=ModelSelect2Widget(
model=Country,
search_fields=['name__icontains'],
)
)

city = forms.ModelChoiceField(
    queryset=City.objects.all(),
    label=u"City",
    widget=ModelSelect2Widget(
        model=City,
        search_fields=['name__icontains'],
        dependent_fields={'country': 'country'},
        max_results=500,
    )
)

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