Snippet List
**What It Is**
This is a JavaScript-based solution to dynamically add and remove forms in formsets and inlineformsets. It requires jQuery.
Originally based on this Snippet: https://djangosnippets.org/snippets/1389/
I have done a lot of work to make it OO, and am using it in production on pages with multiple inlineformsets, and even nested inlineformsets (I call it, "Inlineformset Inception").
My hope is that the code and example are enough to show how it works.
**Usage Details**
In the example usage, I am using a CSS class, 'light', to make every other form have a light background color. My form placeholder is an element with an ID of 'formset-placeholder' (the default). And the form selector is a class name of 'dynamic-form' (the default).
When I have time, I will create a GitHub repository with the code and completed examples.
- django
- javascript
- jquery
- formset
- inlineformset
This method will return an inline formset class that validates values across the given field are unique among all forms. For instance:
ApprovedUserFormSet = inlineformset_factory(Request, ApprovedUser, formset=unique_field_formset('email'), form=ApprovedUserForm)
Will make sure all ApprovedUser objects created for the Request have unique "email" fields.
- field
- unique
- formset
- inlineformset
If you read the docstring and the example you should get a clue what this Code does. I didn't want a big function everytime that handles every specific form, formset combinations so this how i can add/edit Models with specific Forms given to the magic_handle_inlineformsets function. It also works for Forms without innline_formsets.
- forms
- formset
- inline
- inlineformset
- inline_formset
As I was unable to find good examples to render a Form with two or more inlineformsets.
Therefor I have posted this to Django snippets.
This code is little different from another snippet with a Form with one InlineFormSet (the prefixes are necessary in this situation).
The example shows a person's data together with two inline formsets (phonenumbers and addresses) for a person.
You can add, update and delete from this form.
- form
- inline
- inlineformset
- multiple-inlineformsets
As I was unable to find good examples to render an inlineformset together, I have posted this to Django snippets.
The example shows a person's data together with the phonenumbers for that person.
You can add, update and delete from this form.
- form
- inline
- inlineformset
5 snippets posted so far.