jazzband / django-formtools

A set of high-level abstractions for Django forms
https://django-formtools.readthedocs.io
BSD 3-Clause "New" or "Revised" License
794 stars 135 forks source link

FormWizard doesn't work with FormSet/formset_factory() #212

Open murraylchapman opened 2 years ago

murraylchapman commented 2 years ago

If you have a FormWizard step that generates a form(set) via FormSet.form_factory() then you end up with a mess where FormWizard drops a formtools.wizard.views.ManagementForm into the page but it's validated inside Django as if it's a django.forms.formset.ManagementForm.

This manifests as either a "management form has been messed with" error or an KeyError when FormSet.full_clean() does self.management_form.cleaned_data[TOTAL_FORM_COUNT].

I figured out that you can get around this by handing formset_factory a custom FormSet that overrides the non_form_errors() method, but it's a crude fix I'm not sure will be very portable.

IMHO FormWizard should provide a proper FormSet base class for use in formset_factory that creates management forms that will survive validation.