Formless Step in FormWizard

Posted by in Software

Sometimes you’d need to show a purely informational page as part of a FormWizard. As far as I could see, there are two solutions to the problem:

  1. If the info is something like a summary, you have it available in the “success” page (the one after the wizard is finished)
  2. Alternatively, you can make it a page in the wizard.

The more challenging and versatile variant is the second one (versatile because it gives you the possibility to go back to a previous step to correct stuff).

My Solution

My solution is somewhat of an abuse of the FormWizard functionality (but perfectly legal, I assure you).

A Form

First, each step must have a form. So, you need to assign a form class to the “empty form” step. I did it by creating an empty form:

This form needs to be added to your list of steps:

Build Data

Once we’ve built the list of steps, and we have our panel, we need to build some data we can use. To this effect, we use the standard django view approach via context variables. The FormWizard provides us with a context method which we overload:

Using the Data

Cool. Now we have the data available. To use it, we only need to load a custom template. Fortunately, FormWizard allows loading different templates for different steps. To do this, I added a dict of custom templates:

and overloaded the get_template_names() method:

My template looks like this:

Summary

To make this panel work you need to:

  1. Create an empty form and add it to a FormWizard step
  2. Build a template context for the relevant step
  3. Build a custom template and load it

HTH,


A little experiment: If you find this post and ad below useful, please check the ad out :-)