Skip to content

Commit 17ff8c5

Browse files
authored
feat: crispy formsets support (#1275)
1 parent 89f57a8 commit 17ff8c5

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% if formset.non_form_errors %}
2+
{% include "unfold/helpers/messages/error.html" with errors=formset.non_form_errors %}
3+
{% endif %}

src/unfold/templates/unfold_crispy/field.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% if field.is_hidden %}
44
{{ field }}
55
{% else %}
6-
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="group {% if tag == "td" %}align-top border-t border-base-200 font-normal gap-4 min-w-0 overflow-hidden px-3 py-3 text-left dark:border-base-800 dark:before:text-font-important-dark{% endif%} {% if field.errors %}errors{% endif %} {% if field_class %} {{ field_class }}{% endif %} {% if field|is_checkbox and tag == "td" %}flex flex-row gap-2 h-[38px] items-center{% else %}{% if 'form-horizontal' in form_class %} row{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
6+
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="group {% if tag == "td" %}align-top border-t border-base-200 font-normal gap-4 min-w-0 overflow-hidden px-3 py-3 text-left dark:border-base-800 dark:before:text-font-important-dark{% endif%} {% if field.errors %}errors{% endif %} {% if field_class %} {{ field_class }}{% endif %} {% if field|is_checkbox and tag == "td" %}flex flex-row gap-2 items-center{% else %}{% if 'form-horizontal' in form_class %} row{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
77
{% if field.label and not field|is_checkbox and form_show_labels %}
88
<label {% if field.id_for_label %}for="{{ field.id_for_label }}"{% endif %} class="block font-semibold mb-2 text-font-important-light text-sm dark:text-font-important-dark {% if label_class %} {{ label_class }}{% endif %}">
99
{{ field.label }}{% if field.field.required %} <span class="asteriskField">*</span>{% endif %}

src/unfold/templates/unfold_crispy/inputs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% if inputs %}
2-
<div class="border border-base-200 rounded-default flex flex-col gap-2 justify-end p-3 lg:flex-row dark:border-base-800 {{ field_class }}">
2+
<div class="flex flex-col gap-2 justify-end lg:flex-row {{ field_class }}">
33
{% for input in inputs %}
44
{% include "unfold_crispy/layout/baseinput.html" %}
55
{% endfor %}

src/unfold/templates/unfold_crispy/layout/table_inline_formset.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
{% csrf_token %}
1010
{% endif %}
1111

12-
<div class="overflow-x-auto border border-base-200 rounded-default shadow-xs dark:border-base-800" {% if form_id %} id="{{ form_id }}"{% endif %}>
12+
{% include "unfold_crispy/errors_formset.html" %}
13+
14+
<div class="overflow-x-auto border border-base-200 mb-8 rounded-default shadow-xs dark:border-base-800" {% if form_id %} id="{{ form_id }}"{% endif %}>
1315
{{ formset.management_form|crispy }}
1416

1517
<table class="w-full">
@@ -66,10 +68,10 @@
6668
</tbody>
6769
{% endif %}
6870
</table>
69-
70-
{% include "unfold_crispy/inputs.html" %}
7171
</div>
7272

73+
{% include "unfold_crispy/inputs.html" %}
74+
7375
{% if formset_tag %}
7476
</form>
7577
{% endif %}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% load crispy_forms_tags %}
2+
{% load crispy_forms_utils %}
3+
4+
{% specialspaceless %}
5+
{% if formset_tag %}
6+
<form {{ flat_attrs }} method="{{ form_method }}" {% if formset.is_multipart %} enctype="multipart/form-data"{% endif %}>
7+
{% endif %}
8+
{% if formset_method|lower == 'post' and not disable_csrf %}
9+
{% csrf_token %}
10+
{% endif %}
11+
12+
<div>
13+
{{ formset.management_form|crispy }}
14+
</div>
15+
16+
{% include "unfold_crispy/errors_formset.html" %}
17+
18+
{% for form in formset %}
19+
{% include "unfold_crispy/display_form.html" %}
20+
{% endfor %}
21+
22+
{% if inputs %}
23+
<div class="form-actions">
24+
{% for input in inputs %}
25+
{% include "unfold_crispy/layout/baseinput.html" %}
26+
{% endfor %}
27+
</div>
28+
{% endif %}
29+
{% if formset_tag %}</form>{% endif %}
30+
{% endspecialspaceless %}

0 commit comments

Comments
 (0)