-
Notifications
You must be signed in to change notification settings - Fork 317
Closed
Labels
Description
Describe the bug
When using Select2Widget on a field that has empty_label set, the empty_label setting is ignored. I would expect the content of empty_label (if any) as the default value for data-placeholder in the attrs of select2Widget.
Code Snippet
class BookForm(forms.ModelForm):
"""Model Book has field user that is ForeignKey to User."""
class Meta:
model = Book
fields = ["user"]
widgets = {"user": Select2Widget}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["user"].empty_label = "No user is fine too."
# self.fields["user"].widget.attrs['data-placeholder'] = self.fields["user"].empty_label
# Uncomment the line above to make the empty_label appear as the placeholder
To Reproduce
Steps to reproduce the behavior:
- Use the form from the example.
- See that "No user is fine too." does NOT appear.
- Uncomment the line that enables the workaround.
- See that "No user is fine too." DOES appear.
Expected behavior
When a field has an empty_label, I expect that to be the default value for Select2Widget.attrs["data-placeholder"]