Skip to content

Two Interdependent select2 fields reset each other? #229

Closed

Description

@MiroJelev

Goal
I want to make filters for a table that inter depend on each other so that it doesn't matter which filter I choose to start with first.

Problem
The problem comes when I set the filters to depend on each other in the dependent_fields like so:
https://django-select2.readthedocs.io/en/latest/extra.html#interdependent-select2
When I select the first field, everything is okay, but when I click a new value for the second field, it resets (clears) the first field. The same happens when I try the other way around.
Am I missing something?

Cheers!

Code Snippet

class Test1Widget(s2forms.ModelSelect2Widget):
    search_fields = [
        "code__icontains"
    ]
    dependent_fields = {
        "test2": "db__test2",
    }

class Test2Widget(s2forms.ModelSelect2Widget):
    search_fields = [
        "id__icontains"
    ]
    dependent_fields={
        "test1": "db__test1",
    }
test1 = ModelChoiceFilter(queryset=test1.objects.all(), widget=Test1Widget)
test2 = ModelChoiceFilter(queryset=test2.objects.all(), widget=Test2Widget)

Activity

  1. Repository owner locked and limited conversation to collaborators on Aug 23, 2023
  2. converted this issue into a discussion #230 on Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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