【问题标题】:Go to specific step in form wizard转到表单向导中的特定步骤
【发布时间】:2016-04-10 21:45:41
【问题描述】:

是否可以在 FormWizard 表单上添加一个按钮,以将用户引导至向导中的特定步骤?

我显然可以让他们返回或重新开始,但我希望能够提供机会进入特定步骤并更改他们的条目。

【问题讨论】:

    标签: django django-forms django-formwizard


    【解决方案1】:

    是的,这是可能的。最简单的方法是使用NamedUrlWizardView

    如果您使用简单的WizardView,则必须发送值等于步骤名称的wizard_goto_step 参数。

    假设您有 WizardView 和下一步

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

    对于上一步/第一步,您可以使用 {{ wizard.steps.prev }}{{ wizard.steps.first }} 模板变量。

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

    如果您需要特定步骤 - 使用它的名称!

    <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>
    

    【讨论】:

    猜你喜欢
    • 2019-04-18
    • 2017-11-29
    • 1970-01-01
    • 2016-04-02
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多