Skip to content

Commit 4adb956

Browse files
authored
Add missed css_class to layout templates (#28)
1 parent dfaa813 commit 4adb956

File tree

8 files changed

+78
-24
lines changed

8 files changed

+78
-24
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG FOR CRISPY-BOOTSTRAP4
22

3+
## TBC
4+
5+
* Fixed ignoring of `css_class` attribute in `accordion.html`, `accordion-group.html` and `tab.html` templates.
6+
* Bumped the minimum supported version of django-crispy-forms to 2.3.
7+
38
## 2024.1 (2024-02-27)
49

510
* Enabled custom-control checkbox inputs when `show_form_labels` is False.

crispy_bootstrap4/templates/bootstrap4/accordion-group.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="card mb-2">
1+
<div class="card mb-2{% if div.css_class %} {{ div.css_class }}{% endif %}">
22
<div class="card-header" role="tab">
33
<h5 class="mb-0">
44
<a data-toggle="collapse" href="#{{ div.css_id }}" aria-expanded="true"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div id="{{ accordion.css_id }}" role="tablist">
1+
<div{% if accordion.css_class %} class="{{ accordion.css_class }}"{% endif %} id="{{ accordion.css_id }}" role="tablist">
22
{{ content }}
33
</div>

crispy_bootstrap4/templates/bootstrap4/layout/tab.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ul{% if tabs.css_id %} id="{{ tabs.css_id }}"{% endif %} class="nav nav-tabs">
1+
<ul{% if tabs.css_id %} id="{{ tabs.css_id }}"{% endif %} class="nav nav-tabs{% if tabs.css_class %} {{ tabs.css_class }}{% endif %}">
22
{{ links }}
33
</ul>
44
<div class="tab-content card-body">

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_long_description():
3030
license="MIT",
3131
version=VERSION,
3232
packages=["crispy_bootstrap4"],
33-
install_requires=["django-crispy-forms>=2.0", "django>=4.2"],
33+
install_requires=["django-crispy-forms>=2.3", "django>=4.2"],
3434
python_requires=">=3.8",
3535
include_package_data=True,
3636
classifiers=[
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<form method="post">
2+
<ul class="nav nav-tabs test-tab-holder-class">
3+
<li class="nav-item"><a class="nav-link active" href="#custom-name" data-toggle="tab">One</a></li>
4+
<li class="nav-item"><a class="nav-link" href="#two" data-toggle="tab">Two</a></li>
5+
</ul>
6+
<div class="tab-content card-body">
7+
<div id="custom-name" class="tab-pane first-tab-class active">
8+
<div id="div_id_first_name" class="form-group">
9+
<label for="id_first_name" class=" requiredField">first name<span class="asteriskField">*</span> </label>
10+
<div>
11+
<input type="text" name="first_name" maxlength="5" class="textinput textInput inputtext form-control"
12+
required id="id_first_name">
13+
</div>
14+
</div>
15+
</div>
16+
<div id="two" class="tab-pane">
17+
<div id="div_id_password1" class="form-group">
18+
<label for="id_password1" class=" requiredField">password<span class="asteriskField">*</span> </label>
19+
<div>
20+
<input type="password" name="password1" maxlength="30" class="passwordinput form-control"
21+
required id="id_password1">
22+
</div>
23+
</div>
24+
<div id="div_id_password2" class="form-group">
25+
<label for="id_password2" class=" requiredField">re-enter password<span class="asteriskField">*</span> </label>
26+
<div>
27+
<input type="password" name="password2" maxlength="30" class="passwordinput form-control"
28+
required id="id_password2">
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
</form>

tests/test_layout_objects.py

+35-19
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,37 @@ def test_accordion_and_accordiongroup(self):
247247
assert html.count('name="password1"') == 1
248248
assert html.count('name="password2"') == 1
249249

250+
def test_accordion_css_class_is_applied(self):
251+
classes = "one two three"
252+
test_form = SampleForm()
253+
test_form.helper = FormHelper()
254+
test_form.helper.form_tag = False
255+
test_form.helper.layout = Layout(
256+
Accordion(
257+
AccordionGroup("one", "first_name"),
258+
css_class=classes,
259+
css_id="super-accordion",
260+
)
261+
)
262+
html = render_crispy_form(test_form)
263+
264+
assert html.count('<div class="%s" id="super-accordion"' % classes) == 1
265+
266+
def test_accordion_group_css_class_is_applied(self):
267+
classes = "one two three"
268+
test_form = SampleForm()
269+
test_form.helper = FormHelper()
270+
test_form.helper.form_tag = False
271+
test_form.helper.layout = Layout(
272+
Accordion(
273+
AccordionGroup("one", "first_name"),
274+
AccordionGroup("two", "password1", "password2", css_class=classes),
275+
)
276+
)
277+
html = render_crispy_form(test_form)
278+
279+
assert html.count('<div class="card mb-2 %s"' % classes) == 1
280+
250281
def test_accordion_active_false_not_rendered(self):
251282
test_form = SampleForm()
252283
test_form.helper = FormHelper()
@@ -302,30 +333,15 @@ def test_tab_and_tab_holder(self):
302333
"one",
303334
"first_name",
304335
css_id="custom-name",
305-
css_class="first-tab-class active",
336+
css_class="first-tab-class",
306337
),
307338
Tab("two", "password1", "password2"),
339+
css_class="test-tab-holder-class",
308340
)
309341
)
310-
html = render_crispy_form(test_form)
311-
312-
assert (
313-
html.count(
314-
'<ul class="nav nav-tabs"> <li class="nav-item">'
315-
'<a class="nav-link active" href="#custom-name" data-toggle="tab">'
316-
"One</a></li>"
317-
)
318-
== 1
342+
assert parse_form(test_form) == parse_expected(
343+
"bootstrap4/test_layout_objects/test_tab_and_tab_holder.html"
319344
)
320-
assert html.count("tab-pane") == 2
321-
322-
assert html.count('class="tab-pane first-tab-class active"') == 1
323-
324-
assert html.count('<div id="custom-name"') == 1
325-
assert html.count('<div id="two"') == 1
326-
assert html.count('name="first_name"') == 1
327-
assert html.count('name="password1"') == 1
328-
assert html.count('name="password2"') == 1
329345

330346
def test_tab_helper_reuse(self):
331347
# this is a proper form, according to the docs.

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ wheel_build_env = .pkg
1313
deps =
1414
django42: django>=4.2,<5.0
1515
django50: django>=5.0a1,<5.1
16-
crispy2: django-crispy-forms>=2.0
16+
crispy2: django-crispy-forms>=2.3
1717
crispy-latest: https://github.com/django-crispy-forms/django-crispy-forms/archive/main.tar.gz
1818
-rrequirements/testing.txt
1919
commands = python -W error::DeprecationWarning -W error::PendingDeprecationWarning -m pytest {posargs}

0 commit comments

Comments
 (0)