Opened 3 years ago

Last modified 9 months ago

#18830 assigned New feature

FormWizard with Formset and Form Fields mixed on same page

Reported by: jeff@… Owned by: inglesp
Component: Forms Version: 1.4
Severity: Normal Keywords:
Cc: hv@…, thepapermen, bouke, dokterbob Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I would like to request something like the following:
On a given page in a FormWizard, support the ability to mix a formset along with other form fields.

A use-case would be a page in a wizard that lets you add N users to email, and a textarea to customize this email.

The code for such a thing would look like

# Step 1 in wizard
class Step1Form(forms.Form):
    # interesting form fields...

# Form for the email addresses used in Step 2 Formset
class EmailAddressForm(forms.Form):
    email = forms.EmailField()

# Step 2 in wizard
class EmailAddressesAndText(forms.Form):
    emailText = forms.Textarea()
    emailAddressFormSet = formset_factory(EmailAddressForm, can_delete=True, ...)


named_formwizard_forms = (
    ('Step1', Step1Form),
    ('Step2', EmailAddressesAndText),

This would be a very clean way to mix form fields and an embedded formset in a way that can be leveraged as part of the FormWizard found in 1.4


Attachments (1) (4.8 KB) - added by russellm 3 years ago.
Example of a FormContainer that works with FormWizard

Download all attachments as: .zip

Change History (12)

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed
  • Triage Stage changed from Unreviewed to Accepted

I'm going to mark this as accepted, but with a slightly broader scope than you've given the problem.

This problem exists for form wizards, but it also exists for generic views, too. The root of the problem is that you need to be able to combine forms and formsets (or multiple forms and formsets) on a single page. This is true of a page of a wizard, but it's also true of a "FormView" as well.

Now - the nice thing is that Forms and Formsets share a common interface -- that's why you're able to use a formset as a page in a wizard. To my mind, what we need to do here is write a container object that can wrap multiple forms and formsets,

I've done this on some of my own projects, and the approach works fine; I've attached an example of the code you can use to do it. This needs a lot of work to turn it into a feature, but I think it's a feature worth adding.

Changed 3 years ago by russellm

Example of a FormContainer that works with FormWizard

comment:2 Changed 3 years ago by russellm

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:3 Changed 3 years ago by guettli

  • Cc hv@… added

I like the idea of a FormContainer very much.

A FormContainer should be able to contain: Forms, FormFields and FormContainers.

comment:4 Changed 3 years ago by aaugustin

  • Status changed from reopened to new

comment:5 Changed 3 years ago by anonymous

Is this now a upcoming feature?

comment:6 Changed 3 years ago by thepapermen

  • Cc thepapermen added

comment:7 Changed 3 years ago by bouke

  • Cc bouke added

comment:8 Changed 3 years ago by dokterbob

  • Cc dokterbob added

comment:9 Changed 3 years ago by benoitbryon

Could Form, FormSet and FormWizard inherit from some base class (Form or BaseForm)?
If they all inherit from a base class, FormView could support them all!

Note: I don't know if is covered by another ticket.
Also, there is a project that aims to make one form out of several:

How do views handle forms?

  • they use the init(), is_valid() and save() methods
  • templates iterate over sets of fields, iterate over fields, or call unicode()
  • isn't it enough?

I mean, from views "point of view", forms, formsets and "composite forms" are really similar.
Wizards may be a bit different.

comment:10 Changed 16 months ago by anonymous

why not allow forms to contain other forms out of the box, like in WTForms?

comment:11 Changed 9 months ago by inglesp

  • Owner changed from nobody to inglesp
  • Status changed from new to assigned
Note: See TracTickets for help on using tickets.
Back to Top