Code

Ticket #12884: form_wizard.diff

File form_wizard.diff, 1.4 KB (added by Anand Kumria <wildfire@…>, 4 years ago)

patch to allow backwards traversal in FormWizard

Line 
1diff --git a/django/contrib/formtools/wizard.py b/django/contrib/formtools/wizard.py
2index b97e090..c18d7ff 100644
3--- a/django/contrib/formtools/wizard.py
4+++ b/django/contrib/formtools/wizard.py
5@@ -76,7 +76,7 @@ class FormWizard(object):
6             form = self.get_form(current_step, request.POST)
7         else:
8             form = self.get_form(current_step)
9-        if form.is_valid():
10+        if self.advance_form(request, form, current_step) and form.is_valid():
11             self.process_step(request, form, current_step)
12             next_step = current_step + 1
13 
14@@ -217,6 +217,20 @@ class FormWizard(object):
15             previous_fields=previous_fields
16         ), context_instance=RequestContext(request))
17 
18+    def advance_form(self, request, form, step):
19+        """
20+        Hook to decide if the next form in the list should be displayed.
21+
22+        There are occassions when you may want to have a form with a button
23+        that goes backwards. You can make the boolean decision to advance
24+        to the next form, typically, using the existing form and the
25+        current request.
26+
27+        The rationale is that you may want to include the existing form data
28+        when the form is being redisplayed.
29+        """
30+        return True
31+
32     def process_step(self, request, form, step):
33         """
34         Hook for modifying the FormWizard's internal state, given a fully