Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add formset_as_fieldsets template and tests
This creates a partial template which allows for ease of rendering formsets. The template outputs the management form, and wraps each form in a div with appropriate form prefix class attributes.
- Loading branch information
Scott Clark
committed
Aug 22, 2014
1 parent
79de01f
commit 3817362
Showing
5 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
betterforms/templates/betterforms/formset_as_fieldsets.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% block form_head %} | ||
{% if not no_head %} | ||
{% if not csrf_exempt %} | ||
{% csrf_token %} | ||
{% endif %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block form_body %} | ||
{% with formset=form %} | ||
<div class="formSet {{ formset.prefix }}"> | ||
{{ formset.management_form }} | ||
{{ formset.non_form_errors }} | ||
{% for form in formset.forms %} | ||
<div class="formSetForm {{ form.prefix }}"> | ||
{{ form.non_field_errors }} | ||
{# Hack to allow recursive template inclusion #} | ||
{% with fieldset_template_name="betterforms/fieldset_as_div.html" field_template_name="betterforms/field_as_div.html" %} | ||
{% for thing in form %} | ||
{% if thing.is_fieldset %} | ||
{% include fieldset_template_name with fieldset=thing %} | ||
{% else %} | ||
{% include field_template_name with field=thing %} | ||
{% endif %} | ||
{% endfor %} | ||
{% endwith %} | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endwith %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters