fix: Listify initial field value when SearchableField.max_entries == 1 (#4951)
* fix: Listify initial field value when SearchableField.max_entries == 1 * fix: Don't convert initial=None to initial=[None] in has_changed()
This commit is contained in:
parent
de62fd72d9
commit
2993322958
|
@ -320,6 +320,13 @@ class SearchableField(forms.MultipleChoiceField):
|
|||
|
||||
return objs.first() if self.max_entries == 1 else objs
|
||||
|
||||
def has_changed(self, initial, data):
|
||||
# When max_entries == 1, we behave like a ChoiceField so initial will likely be a single
|
||||
# value. Make it a list so MultipleChoiceField's has_changed() can work with it.
|
||||
if initial is not None and self.max_entries == 1 and not isinstance(initial, (list, tuple)):
|
||||
initial = [initial]
|
||||
return super().has_changed(initial, data)
|
||||
|
||||
|
||||
class IETFJSONField(jsonfield.fields.forms.JSONField):
|
||||
def __init__(self, *args, empty_values=jsonfield.fields.forms.JSONField.empty_values,
|
||||
|
|
Loading…
Reference in a new issue