Skip to content

Commit

Permalink
fix #125: IncompleteSelect can't handle collections with siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Apr 5, 2024
1 parent 9c44f7b commit 8a1a2fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions formset/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@ class FormCollection(BaseFormCollection, metaclass=FormCollectionMeta):
`django.forms.forms.BaseForm` are managed by this class.
"""
def get_field(self, field_path):
path = field_path.split('.', 1)
key, path = path
if self.has_many:
path = field_path.split('.', 2)
index, key, path = path
int(index) # raises ValueError if index is not an integer
else:
path = field_path.split('.', 1)
key, path = path
return self.declared_holders[key].get_field(path)
2 changes: 1 addition & 1 deletion formset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _fetch_options(self, request):
field_path = request.GET['field']
try:
field = self.get_field(field_path)
except KeyError:
except (KeyError, ValueError):
return HttpResponseBadRequest(f"No such field: {field_path}")
assert isinstance(field.widget, (Selectize, DualSelector))
widget = field.widget
Expand Down

0 comments on commit 8a1a2fe

Please sign in to comment.