I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied.
The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want to skip that step instead of showing an empty list of promotions.
So I want to have 2 possible flows:
step1 - step2 - step3
step1 - step3
The hook method process_step() gives you exactly that opportunity. After the form is validated you can modify the self.form_list variable, and delete the forms you don't need.
Needles to say if you logic is very complicated, you are better served creating separate views for each step/form, and forgoing the FormWizard altogether.
To make certain forms optional you can introduce conditionals in the list of forms you pass to the FormView in your urls.py:
contact_forms = [ContactForm1, ContactForm2]
urlpatterns = patterns('',
(r'^contact/$', ContactWizard.as_view(contact_forms,
condition_dict={'1': show_message_form_condition}
)),
)
For a full example see the Django docs: https://django-formtools.readthedocs.io/en/latest/wizard.html#conditionally-view-skip-specific-steps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With