django-select2 icon indicating copy to clipboard operation
django-select2 copied to clipboard

`empty_label` not displayed for `ModelSelect2MultipleWidget`

Open rez0n opened this issue 3 years ago • 1 comments

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 avatar Nov 09 '22 18:11 rez0n

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

codingjoe avatar Nov 23 '22 18:11 codingjoe