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

Fix TemplateDoesNotExist when using MultiField (#75) #191

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 3 additions & 27 deletions crispy_bootstrap5/templates/bootstrap5/layout/multifield.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
{% load crispy_forms_field %}

{% if field.is_hidden %}
{{ field }}
{% else %}

{% if field.label %}
<label for="{{ field.id_for_label }}"{% if labelclass %} class="{{ labelclass }}"{% endif %}>
{% endif %}

{% if field|is_checkbox %}
{% crispy_field field %}
{% endif %}

{% if field.label %}
{{ field.label }}
{% endif %}

{% if not field|is_checkbox %}
{% crispy_field field %}
{% endif %}

{% if field.label %}
</label>
{% endif %}

{% endif %}
<div class="d-flex gap-2">
{{ fields_output }}
</div>
5 changes: 5 additions & 0 deletions crispy_bootstrap5/templates/bootstrap5/multifield.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load crispy_forms_field %}

<div>
{% include 'bootstrap5/field.html' %}
</div>
14 changes: 13 additions & 1 deletion tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
TabHolder,
)
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Field, Layout, MultiWidgetField
from crispy_forms.layout import HTML, Field, Layout, MultiField, MultiWidgetField
from crispy_forms.utils import render_crispy_form
from django import forms
from django.template import Context, Template
Expand Down Expand Up @@ -542,6 +542,18 @@ def test_hidden_fields(self):
assert html.count('type="hidden"') == 5
assert html.count("<label") == 0

def test_multifield(self):
test_form = SampleForm()
test_form.helper = FormHelper()
test_form.helper.layout = Layout(
MultiField("", "password1", "password2")
)
html = render_crispy_form(test_form)
assert test_form["password1"].label in html
assert test_form["password2"].label in html
assert html.count("<input") == 2
assert html.count('type="password"') == 2

def test_multiplecheckboxes(self):
test_form = CheckboxesSampleForm()
html = render_crispy_form(test_form)
Expand Down
Loading