Skip to content

Commit

Permalink
[IMP] Add table_formset template
Browse files Browse the repository at this point in the history
  • Loading branch information
DaeronAlagos committed Feb 10, 2024
1 parent 89e74e5 commit 6340f8f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
57 changes: 57 additions & 0 deletions crispy_bulma/templates/bulma/table_inline_formset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% load crispy_forms_tags %}
{% load crispy_forms_utils %}
{% load crispy_forms_field %}

{% specialspaceless %}
{% if formset_tag %}
<form {{ flat_attrs }} method="{{ form_method }}" {% if formset.is_multipart %} enctype="multipart/form-data"{% endif %}>
{% endif %}
{% if formset_method|lower == 'post' and not disable_csrf %}
{% csrf_token %}
{% endif %}

<div>
{{ formset.management_form|crispy }}
</div>

<table{% if form_id %} id="{{ form_id }}_table"{% endif%} class="table table-striped table-sm">
<thead>
{% if formset.readonly and not formset.queryset.exists %}
{% else %}
<tr>
{% for field in formset.forms.0 %}
{% if field.label and not field.is_hidden %}
<th for="{{ field.auto_id }}" class="{% if field.field.required %}requiredField{% endif %}">
{{ field.label }}{% if field.field.required and not field|is_checkbox %}<span class="asteriskField">*</span>{% endif %}
</th>
{% endif %}
{% endfor %}
</tr>
{% endif %}
</thead>

<tbody>
<tr class="d-none empty-form">
{% for field in formset.empty_form %}
{% include 'bulma/field.html' with tag="td" form_show_labels=False %}
{% endfor %}
</tr>

{% for form in formset %}
{% if form_show_errors and not form.is_extra %}
{% include "bulma/errors.html" %}
{% endif %}

<tr>
{% for field in form %}
{% include 'bulma/field.html' with tag="td" form_show_labels=False %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

{% include "bulma/inputs.html" %}

{% if formset_tag %}</form>{% endif %}
{% endspecialspaceless %}
4 changes: 2 additions & 2 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def test_tabular_formset_layout():
SampleFormSet = formset_factory(SampleForm, extra=3)
formset = SampleFormSet()
formset.helper = FormHelper()
formset.helper.template = "bootstrap5/table_inline_formset.html"
formset.helper.template = "bulma/table_inline_formset.html"
assert parse_form(formset) == parse_expected("test_tabular_formset_layout.html")

SampleFormSet = formset_factory(SampleForm, extra=3)
Expand All @@ -522,7 +522,7 @@ def test_tabular_formset_layout():
}
formset = SampleFormSet(data)
formset.helper = FormHelper()
formset.helper.template = "bootstrap5/table_inline_formset.html"
formset.helper.template = "bulma/table_inline_formset.html"
assert parse_form(formset) == parse_expected(
"test_tabular_formset_layout_failing.html"
)
Expand Down

0 comments on commit 6340f8f

Please sign in to comment.