Opened 12 years ago
Closed 15 months ago
#18830 closed New feature (wontfix)
FormWizard with Formset and Form Fields mixed on same page
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | hv@…, thepapermen, Bouke Haarsma, Mathijs de Bruin | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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
forms.py
# 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, ...)
in urls.py
## 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
Thanks!
Attachments (1)
Change History (14)
comment:1 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Triage Stage: | Unreviewed → Accepted |
by , 12 years ago
Attachment: | form_container.py added |
---|
Example of a FormContainer that works with FormWizard
comment:2 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:3 by , 12 years ago
Cc: | added |
---|
I like the idea of a FormContainer very much.
A FormContainer should be able to contain: Forms, FormFields and FormContainers.
comment:4 by , 12 years ago
Status: | reopened → new |
---|
comment:6 by , 12 years ago
Cc: | added |
---|
comment:7 by , 12 years ago
Cc: | added |
---|
comment:8 by , 11 years ago
Cc: | added |
---|
comment:9 by , 11 years ago
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: https://pypi.python.org/pypi/django-composite-form/
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 by , 10 years ago
why not allow forms to contain other forms out of the box, like in WTForms?
follow-up: 12 comment:11 by , 7 years ago
Is this still something people want?
I'm investigating doing something along these lines at work, to move away from an inflexible solution conceived under time constraints.
the WTForm pattern looks like the easiest pattern to implement as a library, though it will probably cause issues with third-party form renderers, such as django-bootstrap3.
I'll see how far this can be taken using Form wrappers, working in a similar fashion to how a MutliValueField works.
comment:12 by , 7 years ago
Replying to Anthony King:
Is this still something people want?
I'm investigating doing something along these lines at work, to move away from an inflexible solution conceived under time constraints.
the WTForm pattern looks like the easiest pattern to implement as a library, though it will probably cause issues with third-party form renderers, such as django-bootstrap3.
I'll see how far this can be taken using Form wrappers, working in a similar fashion to how a MutliValueField works.
Yes, I want something like this. In particular I am missing a container for N django forms.
comment:13 by , 15 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Triage Stage: | Accepted → Unreviewed |
The idea behind this feature is quite fuzzy. It sounds like a third-party package is the best way to proceed as it doesn't need to be included in Django itself.
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.