Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed formactions template to consider arguments #187

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div{% if formactions.attrs %} {{ formactions.flat_attrs }}{% endif %} class="mb-3">
<div
{% if formactions.flat_attrs %}{{ formactions.flat_attrs }}{% endif %}
class="mb-3{% if 'form-horizontal' in form_class %} row{% endif %} {{ formactions.css_class|default:'' }} {{ field_class }}"
{% if formactions.id %} id="{{ formactions.id }}"{% endif %}>
{% if label_class %}
<div class="aab {{ label_class }}"></div>
{% endif %}

<div class="{{ field_class }}">
{{ fields_output|safe }}
</div>
Expand Down
8 changes: 8 additions & 0 deletions tests/results/test_formactions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div
test="formactions-test"
class="mb-3 formactions-test-class field-class"
id="formactions-test-id">
<div class="field-class">
<b>test</b>
</div>
</div>
45 changes: 44 additions & 1 deletion tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Alert,
AppendedText,
FieldWithButtons,
FormActions,
InlineCheckboxes,
InlineField,
InlineRadios,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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("<b>test</b>"),
),
)

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("<b>test</b>"),
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("<b>test</b>"),
css_class="formactions-test-class",
),
)

expected_class = 'class="mb-3 row formactions-test-class "'
assert expected_class in render_crispy_form(test_form)
Loading