Skip to content

Commit

Permalink
Prevent literal "None" placeholders (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benbb96 committed Feb 25, 2020
1 parent 39ab326 commit e7fa49a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<option value=""></option>' not in multiple_select.widget.render('featured_artists', None)
output = multiple_select.widget.render('featured_artists', None)
assert '<option value=""></option>' not in output
assert 'data-placeholder=""' in output

def test_i18n(self):
translation.activate('de')
Expand Down

0 comments on commit e7fa49a

Please sign in to comment.