I have several forms that I added to the wizard, but the state of the form is only supported for the last step, and done () is not executed.
I created the following, heavily based on django documentation examples, to try and figure this out. The last step seems to be the only one that keeps state when moving between steps.
class OneForm( Form ): field_one = forms.CharField(label='1', max_length=100) field_two = forms.CharField(label='2', max_length=100) field_three = forms.CharField(label='3', max_length=100) class TwoForm( Form ): field_one = forms.CharField(label='4', max_length=100) field_two = forms.CharField(label='5', max_length=100) field_three = forms.CharField(label='6', max_length=100) TEST_WIZARD_FORMS = [ ("one", OneForm), ("two", TwoForm), ] TEST_TEMPLATES = { 'one': 'tour/one.html', 'two': 'tour/two.html', } class TestWizardView( SessionWizardView ): form_list = TEST_WIZARD_FORMS def done(self, form_list, **kwargs): print('done executed') return reverse('home') def get_template_names(self): return [TEST_TEMPLATES[self.steps.current]]
and this is for templates (both one.html and two.html are identical)
<html> <body> <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 }} {{ wizard.form.non_field_errors }} {{ wizard.form.errors }} {% for form in wizard.form.forms %} {{ form }} {% endfor %} {% else %} {{ wizard.form }} {% endif %} </table> {% if wizard.steps.prev %} <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">"first step"</button> <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">"prev step"</button> {% endif %} <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.next }}">"next step"</button> <input type="submit" value="submit"/> </form> </body> </html>
If I enter the data in step 1, go to step 2 and enter the data, and then go back to step 1, the first step will not save the data and will not display form errors. When I click next to returning to step 2, the data of the second step is still present. The deliberate placement of invalid data in step 1 showed me that it also does not confirm the form, as the wizard proceeds to step 2 without displaying errors.
When I submit the form, done () is not executed. It makes sense if only the last step was really successful, but the lack of errors in step 1 puzzled me.
Why are these forms not supported, except in the final form? Why is the last step the only one that actually validates the form data? Why is this not done?
Update:. It seems that form validation happens after everything, and I see that it succeeds by printing the relevant information in the post function, but done () still fails.
Thanks.