Search code examples
djangoformsdjango-formsdjango-formwizard

form wizard does not show the next button


I am trying to use django form wizard where I have a form split over multiple pages. I have bene trying to piece together something from their documentation. So, currently, I have the following forms:

class DummyForm(ModelForm):
    class Meta:
        model = DummyModel
        fields = ['name', 'description', 'time_points']

    def __init__(self, *args, **kwargs):
        super(DummyForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-sm-2'
        self.helper.field_class = 'col-sm-10'
        self.helper.layout = Layout(
            Field('name'),
            Field('description'),
            Field('time_points')) 


class OtherForm(ModelForm):
    class Meta:
        model = DummyModel
        fields = ['more_text']

    def __init__(self, *args, **kwargs):
        super(DummyForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-sm-2'
        self.helper.field_class = 'col-sm-10'
        self.helper.layout = Layout(
            Field('More_text'))

I have the views and urls configured as follows:

views.py

from django.http import HttpResponseRedirect
class ContactWizard(SessionWizardView):
    def get_template_names(self):
        return "test.html"

    def done(self, form_list, **kwargs):
        return HttpResponseRedirect('index')

urls.py

url(r'^contact/$', views.ContactWizard.as_view([DummyForm, OtherForm]))

Finally, my test.html template looks like:

{% extends "base.html" %}
{% load i18n %}

{% block content %}
<p>Step {{ wizard.steps.current }} 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 %}
        {{ form }}
    {% endfor %}
{% else %}
    {{ wizard.form }}
{% endif %}
{% if wizard.steps.prev %}
<button name="wizard_prev_step" value="{{ wizard.steps.first }}">{% trans "first step" %}</button>
<button name="wizard_prev_step" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>
{% endif %}
</table>
<input type="submit">
</form>
{% endblock %}

I am not sure I completely understand the template code but I was expecting a button to move to the next form. Instead, I only see the submit button as you see in the screenshot.

Can anyone see what I have done incorrectly? The form only seems to render the first form and there is no way to navigate.

enter image description here


Solution

  • When the submit button is pressed, the form wizard will move the user to the next step if the form is valid.

    If you want to change the name of the submit button then you could change

    <input type="submit">
    

    to

    <input type="submit" value="Next">