Go to specific step in form wizard
Asked Answered
B

1

7

Is it possible to add a button on a FormWizard form which can direct the user to a specific step in the wizard?

I can obviously get them to go back or start again but I'd like to be able to offer the chance to go to a specific step and change their entries.

Bivalve answered 6/1, 2016 at 17:38 Comment(0)
R
7

Yes, it's possible. Simplest way is to use NamedUrlWizardView

If you use simple WizardView, you have to send wizard_goto_step parameter with a value equal to step name.

Let's say you have WizardView with steps like next

class OrderWizardView(SessionWizardView):
    form_list = (
        ('select_customer', forms.WizardCustomerForm),
        ('products', forms.WizardProductFormset),
        ('order', forms.WizardOrderForm),
        ('customer', forms.WizardCustomerDetailsForm),
        ('review', forms.WizardReviewForm),
    )

For Previous/First step you can use {{ wizard.steps.prev }} and {{ wizard.steps.first }} template variables.

<button name="wizard_goto_step" value="{{ wizard.steps.first }}">First Step</button>
<button name="wizard_goto_step" value="{{ wizard.steps.prev }}">Prev Step</button>

If you need a specific step - use its name!

<button name="wizard_goto_step" value="select_customer">Select customer</button>
<button name="wizard_goto_step" value="products">Add products</button>
...
<button name="wizard_goto_step" value="review">Review</button>
Rondeau answered 26/8, 2017 at 15:42 Comment(2)
How can I use it with <a> tag?Shedevil
check docs for NamedUrlWizardView.get_step_url django-formtools.readthedocs.io/en/latest/…Rondeau

© 2022 - 2024 — McMap. All rights reserved.