- Django form wizard - customized form layout for each step
- {% block content %}
- # block step: variable text for each step
- {% block step %}{% endblock %}
- <p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
- <form action="" method="post">{% csrf_token %}
- <table>
- {{ wizard.management_form }}
- {% if wizard.form.forms %}
- {{ wizard.form.management_form }}
- {% for form in wizard.form.forms %}
- # block form_if: shows a complete customized form layout for each step
- {% block form_if %}{% endblock %}
- {% endfor %}
- {% else %}
- # block form_else: shows a complete customized form layout for each step
- {% block form_else %}{% endblock %}
- {% endif %}
- </table>
- {% if wizard.steps.prev %}
- <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">{% trans "first step" %}</button>
- <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>
- {% endif %}
- <input type="submit" value="{% trans "submit" %}"/>
- </form>
- {% endblock %}
- {{ wizard.management_form }}
- {% if wizard.form.forms %}
- {{ wizard.form.management_form }}
- {% for form in wizard.form.forms %}
- # block form_if: shows a complete customized form layout for each step
- {% with myform=form %}
- {% block form_if %}{% endblock %}
- {%e endwith %}
- {% endfor %}
- {% else %}
- # block form_else: shows a complete customized form layout for each step
- {% with myform=form %}
- {% block form_else %}{% endblock %}
- {% endwith %}
- {% endif %}
- class TestFormWizard(SessionWizardView):
- def get_template_names(self):
- if self.steps.current == 1:
- return 'step1_form.html'
- if self.steps.current == 2:
- return 'step2_form.html'
- return 'wz_form.html'
- <form enctype="multipart/form-data" action="" method="post">{% csrf_token %}
- <table>
- {{ wizard.management_form }}
- {% if wizard.form.forms %}
- {{ wizard.form.management_form }}
- {% for form in wizard.form.forms %}
- <!-- block below accesses a customized form layout for each step -->
- {% block form_if %}{% endblock %}
- {% endfor %}
- {% else %}
- <!-- block below accesses a customized form layout for each step -->
- <!-- using the with statement makes it possible to use the same layout used in the form_if block -->
- {% with form=wizard.form %}
- {% block form_else %}{% endblock %}
- {% endwith %}
- {% endif %}
- </table>
- {% if wizard.steps.prev %}
- <button name="wizard_goto_step" value="{{ wizard.steps.first }}" class="button">{% trans "first step" %}</button>
- <button name="wizard_goto_step" value="{{ wizard.steps.prev }}" class="button">{% trans "prev step" %}</button>
- {% endif %}
- <div>
- <input type="submit" value="{% trans "submit" %}" class="button"/>
- </div>
- </form>
- {% extends "base_wizard.html" %}
- {% block form_if %}{% block form_else %}
- <fieldset>
- <legend>Title</legend>
- <div>
- <label>{{ form.field.label }}:<p class="note">{{ form.field.help_text }}</p></label> {{ form.field }}
- <p class="error">
- {% if form.field.errors %}
- {% for error in form.field.errors %}
- {{ error }}
- {% endfor %}
- {% endif %}
- </p>
- </div>
- </fieldset>
- {% endblock %}{% endblock %}