Skip to content

Commit 271cfdb

Browse files
lucastheissmithdc1
andauthored
Fix TemplateDoesNotExist when using MultiField (#75) (#191)
Co-authored-by: David Smith <[email protected]>
1 parent 1aed40a commit 271cfdb

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed
Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
{% load crispy_forms_field %}
2-
3-
{% if field.is_hidden %}
4-
{{ field }}
5-
{% else %}
6-
7-
{% if field.label %}
8-
<label for="{{ field.id_for_label }}"{% if labelclass %} class="{{ labelclass }}"{% endif %}>
9-
{% endif %}
10-
11-
{% if field|is_checkbox %}
12-
{% crispy_field field %}
13-
{% endif %}
14-
15-
{% if field.label %}
16-
{{ field.label }}
17-
{% endif %}
18-
19-
{% if not field|is_checkbox %}
20-
{% crispy_field field %}
21-
{% endif %}
22-
23-
{% if field.label %}
24-
</label>
25-
{% endif %}
26-
27-
{% endif %}
1+
<div class="d-flex gap-2">
2+
{{ fields_output }}
3+
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>{% include 'bootstrap5/field.html' %}</div>

tests/results/test_multifield.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<form method="post">
2+
<div class="d-flex gap-2">
3+
<div>
4+
<div id="div_id_password1" class="mb-3">
5+
<label for="id_password1" class="form-label requiredField">password<span class="asteriskField">*</span> </label>
6+
<input type="password" name="password1" maxlength="30" class="passwordinput form-control" required id="id_password1">
7+
</div>
8+
</div>
9+
<div>
10+
<div id="div_id_password2" class="mb-3">
11+
<label for="id_password2" class="form-label requiredField">re-enter password<span class="asteriskField">*</span></label>
12+
<input type="password" name="password2" maxlength="30" class="passwordinput form-control" required id="id_password2">
13+
</div>
14+
</div>
15+
</div>
16+
</form>

tests/test_layout_objects.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
TabHolder,
2121
)
2222
from crispy_forms.helper import FormHelper
23-
from crispy_forms.layout import HTML, Field, Layout, MultiWidgetField
23+
from crispy_forms.layout import HTML, Field, Layout, MultiField, MultiWidgetField
2424
from crispy_forms.utils import render_crispy_form
2525
from django import forms
2626
from django.template import Context, Template
@@ -542,6 +542,12 @@ def test_hidden_fields(self):
542542
assert html.count('type="hidden"') == 5
543543
assert html.count("<label") == 0
544544

545+
def test_multifield(self):
546+
test_form = SampleForm()
547+
test_form.helper = FormHelper()
548+
test_form.helper.layout = Layout(MultiField("", "password1", "password2"))
549+
assert parse_form(test_form) == parse_expected("test_multifield.html")
550+
545551
def test_multiplecheckboxes(self):
546552
test_form = CheckboxesSampleForm()
547553
html = render_crispy_form(test_form)

0 commit comments

Comments
 (0)