Open gchp opened 10 years ago
Should forms that are swapped out dynamically be provided in the initial wizard definition as None? This makes sense to me, but it will require some other changes. For example, https://github.com/django/django-formtools/blob/master/formtools/wizard/views.py#L178 errors out if None is passed for the form.
Something like:
WIZARD_FORMS = (
...
("foo", None),
...
)
wizard_view = WizardView.as_view(WIZARD_FORMS)
If we allow None as a placeholder, then we can't guarantee this check is thrown: https://github.com/django/django-formtools/blob/master/formtools/wizard/views.py#L187
But with swappable form classes it really isn't guaranteed anyways.
This issue was originally submitted on Trac (#21667). I've added some snippets from the original ticket below, see the link above for the full conversation.
The WizardView does not currently support dynamic form classes without overriding the entire get_form method.
My mixin below demonstrates an easy way to make this convenient. I needed this functionality to support using modelform_factory at runtime to accommodate logic that varies depending on choices made previously in the wizard. A simple use case is to support dynamic "required" fields.
This is a simple demonstration of usage: