diff --git a/django_select2/forms.py b/django_select2/forms.py index 1fa858a7..b21bee4b 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -80,7 +80,7 @@ def build_attrs(self, base_attrs, extra_attrs=None): default_attrs['data-allow-clear'] = 'false' else: default_attrs['data-allow-clear'] = 'true' - default_attrs['data-placeholder'] = self.empty_label + default_attrs['data-placeholder'] = self.empty_label or "" default_attrs.update(base_attrs) attrs = super().build_attrs(default_attrs, extra_attrs=extra_attrs) diff --git a/tests/test_forms.py b/tests/test_forms.py index 797dfd4c..d07c381b 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -95,7 +95,9 @@ def test_empty_option(self, db): multiple_select = self.multiple_form.fields['featured_artists'] assert multiple_select.required is False assert multiple_select.widget.allow_multiple_selected - assert '' not in multiple_select.widget.render('featured_artists', None) + output = multiple_select.widget.render('featured_artists', None) + assert '' not in output + assert 'data-placeholder=""' in output def test_i18n(self): translation.activate('de')