Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty_label not displayed for ModelSelect2MultipleWidget #174

Open
rez0n opened this issue Nov 9, 2022 · 1 comment
Open

empty_label not displayed for ModelSelect2MultipleWidget #174

rez0n opened this issue Nov 9, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rez0n
Copy link
Sponsor

rez0n commented Nov 9, 2022

Describe the bug
Hi @codingjoe
I assume it is something related to this issue.
empty_label is not displays for the ModelSelect2MultipleWidget on page loads, but if I select one of options and then clear selection it gonna showed.

Code Snippet

field_name = forms.ModelChoiceField(
        required=False,
        blank=True,
        queryset=Organisation.objects.all(),
        widget=OrganisationsPickWidget(
            attrs={
                'class': 'form-control',
                'data-minimum-input-length': 0,
            },
        ),
    )

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fields['field_name'].empty_label = 'empty_label text'

Screenshots

Open.
2022-11-09 at 20 09 00

Select.
2022-11-09 at 20 09 16

Cleared selection
2022-11-09 at 20 09 53

Thanks in advance.

@rez0n rez0n added the bug Something isn't working label Nov 9, 2022
@codingjoe
Copy link
Owner

Hi @rez0n,

Interesting. Yes, I believe you are right, that doesn't work right now. Select2 doesn't really support empty options, since it'll be simply empty. However, you could use the placeholder, right? I actually don't know how Django handles the empty label on a native multiple select.

@rez0n, as a frequent contributor and sponsor, do you want to contribute this yourself? Or do you want me to take a swing?

Cheers,
Joe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants