Skip to content

Correctly render selected choice for ListSelect2 grouped fields #1299

@j-bernard

Description

@j-bernard

ListSelect2 does not correctly render the selected choices when used with groups.

This snippet works for groups but I did not make a PR as I'll let the way to detect or declare grouped vs non-grouped to you.

class LgrGroupedListSelect2(autocomplete.ListSelect2):

    def filter_choices_to_render(self, selected_choices):
        # dal.widget.WidgetMixin.filter_choices_to_render does not handle correctly grouped lists
        ch = []
        for group in self.choices:
            c = [c for c in group[1] if str(c[0]) in selected_choices]
            ch.extend(c)
        self.choices = ch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions