Skip to content
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
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>
1 change: 1 addition & 0 deletions crispy_bootstrap5/templates/bootstrap5/multifield.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>{% include 'bootstrap5/field.html' %}</div>
16 changes: 16 additions & 0 deletions tests/results/test_multifield.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<form method="post">
<div class="d-flex gap-2">
<div>
<div id="div_id_password1" class="mb-3">
<label for="id_password1" class="form-label requiredField">password<span class="asteriskField">*</span> </label>
<input type="password" name="password1" maxlength="30" class="passwordinput form-control" required id="id_password1">
</div>
</div>
<div>
<div id="div_id_password2" class="mb-3">
<label for="id_password2" class="form-label requiredField">re-enter password<span class="asteriskField">*</span></label>
<input type="password" name="password2" maxlength="30" class="passwordinput form-control" required id="id_password2">
</div>
</div>
</div>
</form>
8 changes: 7 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,12 @@ 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"))
assert parse_form(test_form) == parse_expected("test_multifield.html")

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