Skip to content

Commit 2993322

Browse files
fix: Listify initial field value when SearchableField.max_entries == 1 (ietf-tools#4951)
* fix: Listify initial field value when SearchableField.max_entries == 1 * fix: Don't convert initial=None to initial=[None] in has_changed()
1 parent de62fd7 commit 2993322

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

ietf/utils/fields.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ def clean(self, pks):
320320

321321
return objs.first() if self.max_entries == 1 else objs
322322

323+
def has_changed(self, initial, data):
324+
# When max_entries == 1, we behave like a ChoiceField so initial will likely be a single
325+
# value. Make it a list so MultipleChoiceField's has_changed() can work with it.
326+
if initial is not None and self.max_entries == 1 and not isinstance(initial, (list, tuple)):
327+
initial = [initial]
328+
return super().has_changed(initial, data)
329+
323330

324331
class IETFJSONField(jsonfield.fields.forms.JSONField):
325332
def __init__(self, *args, empty_values=jsonfield.fields.forms.JSONField.empty_values,

0 commit comments

Comments
 (0)