Reputation: 2723
Is it possible to prevent Django from rendering an empty inline form of a formset?
In the template, which displays the form, I have among others:
{{ formset }}
{{ formset.management_form }}
Consider the following requirement:
A visitor opens the page for the first time, and the form is rendered.
In this case, Django ALWAYS renders an empty inline form. Can I specify that no forms from the formset should be displayed? I have JavaScript code in place, which handles adding new inline forms whenever the user requests them.
The visitor submits the form, but there are errors in it.
The form is shown again, and the items he provided earlier in the formset appear as inline forms. Which is correct.
Upvotes: 2
Views: 888
Reputation: 1124
See the django Documenttation on formsets https://docs.djangoproject.com/en/1.4/topics/forms/formsets/
ArticleFormSet = formset_factory(ArticleForm, extra=2, max_num=1)
the extra parameter defines the number of additional empty forms
Upvotes: 2