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

Dynamically insert wizard steps based on form data #199

Closed CruzR closed 3 years ago

CruzR commented 3 years ago

I'd like to dynamically insert wizard steps based on form data from an earlier step. To be more specific, I have a ModelMultipleChoiceField in one step, and I'd like to insert a step for each selected model. As I understand it, the only way to have some kind of dynamic step selection right now is the condition_dict mechanism, which won't work because it can only skip steps known to exist in advance. FormSets or ModelFormSets also don't work for my use case because the form inserted should not be a form for the chosen model instance, but rather a form determined by an attribute of the chosen model instance.

I think for now I can probably work around this, either by defining a maximum number of steps and skipping each that does not have a corresponding model in the choice field, or by subclassing WizardView in order to allow dynamic step insertion.

But if this is something that might be interesting to have in django-formtools proper, maybe we can discuss how to implement this and I can prepare a PR.

claudep commented 3 years ago

Frankly, I think that the use case is too specific to integrate something like that in WizardView. So your suggestion to subclass WizardView looks right to me. If by doing this, you see possible improvements, you may open new tickets with such proposals.

CruzR commented 3 years ago

Alright, I'll do that then. Thanks for the quick reply!

schinckel commented 3 years ago

If it helps, I had to do exactly this.

The only thing I really needed to change was to make get_form() use get_form_list() instead of how it currently references things.