From 00e741c37acbac4d54e2d8de80d647bcd350c23a Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:39:41 +0100 Subject: [PATCH] Fixed formactions template to consider arguments (#187) Co-authored-by: Matthias Schoettle --- CHANGELOG.md | 1 + .../bootstrap5/layout/formactions.html | 6 ++- tests/results/test_formactions.html | 8 ++++ tests/test_layout_objects.py | 45 ++++++++++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 tests/results/test_formactions.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fa3730..3186206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Added support for Django 5.1. * Fixed `accordion.html`, `accordion-group.html` and `tab.html` templates to render `css_class` attribute. * Dropped support for django-crispy-forms 2.2 and earlier. +* FormActions template improvements. The template now considers the `css_class` argument and adds the `row` class for Horizontal forms. ## 2024.2 (2024-02-24) diff --git a/crispy_bootstrap5/templates/bootstrap5/layout/formactions.html b/crispy_bootstrap5/templates/bootstrap5/layout/formactions.html index d40fca5..6daaa07 100644 --- a/crispy_bootstrap5/templates/bootstrap5/layout/formactions.html +++ b/crispy_bootstrap5/templates/bootstrap5/layout/formactions.html @@ -1,8 +1,10 @@ - +
{% if label_class %}
{% endif %} -
{{ fields_output|safe }}
diff --git a/tests/results/test_formactions.html b/tests/results/test_formactions.html new file mode 100644 index 0000000..e9c294c --- /dev/null +++ b/tests/results/test_formactions.html @@ -0,0 +1,8 @@ +
+
+ test +
+
diff --git a/tests/test_layout_objects.py b/tests/test_layout_objects.py index 6f3cdbf..1ca8a12 100644 --- a/tests/test_layout_objects.py +++ b/tests/test_layout_objects.py @@ -8,6 +8,7 @@ Alert, AppendedText, FieldWithButtons, + FormActions, InlineCheckboxes, InlineField, InlineRadios, @@ -200,7 +201,6 @@ def test_custom_django_widget(self): form.helper.layout = Layout("inline_radios") html = render_crispy_form(form) - print(html) assert 'class="form-check-input"' in html # Make sure an inherited CheckboxSelectMultiple gets rendered as it @@ -662,3 +662,46 @@ def test_inline_checkboxes(self): form.helper = FormHelper() form.helper.layout = InlineRadios("checkboxes") assert parse_form(form) == parse_expected("inline_checkboxes.html") + + def test_formactions(self): + test_form = SampleForm() + test_form.helper = FormHelper() + test_form.helper.form_tag = False + test_form.helper.layout = Layout( + FormActions( + HTML("test"), + ), + ) + + assert 'class="mb-3 "' in render_crispy_form(test_form) + + def test_formactions_attrs(self): + test_form = SampleForm() + test_form.helper = FormHelper() + test_form.helper.form_tag = False + test_form.helper.field_class = "field-class" + test_form.helper.layout = Layout( + FormActions( + HTML("test"), + css_class="formactions-test-class", + css_id="formactions-test-id", + test="formactions-test", + ), + ) + + assert parse_form(test_form) == parse_expected("test_formactions.html") + + def test_formactions_horizontal_form(self): + test_form = SampleForm() + test_form.helper = FormHelper() + test_form.helper.form_tag = False + test_form.helper.form_class = 'form-horizontal' + test_form.helper.layout = Layout( + FormActions( + HTML("test"), + css_class="formactions-test-class", + ), + ) + + expected_class = 'class="mb-3 row formactions-test-class "' + assert expected_class in render_crispy_form(test_form)