At the moment I'm experimenting with django form wizard. The basic set-up works now and I'm able to call different templates for each step showing variable text.
Now I want to take it a step further and create a customized form layout for each step. The documentation of Django shows a generic way to show the form, always with vertical alignment.
In my experiment I have two steps:
- step 1: email and password (just two fields needing vertical alignment)
- step 2: personal data: address, profession, ...
So for the step 2 I want to use a complete different form layout then step 1: using fieldsets, horizontal alignment of field (eg address: street and number), ...
Starting from the django documentation I suppose that the below can work (did not test it yet):
{% 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 %}
But the problem I have here is that I have two blocks
: form_if
and form_else
calling the same form layout. So then I have double maintenance of my form layout.
Are there better ways to accomplish what I want to achieve?
Thanks!
Kind Regards