Skip to content

Commit

Permalink
Add modal template and tests (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxwxnvermx authored Nov 16, 2023
1 parent 739f5b7 commit 2737939
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next Release

* Added support for [Switches](https://getbootstrap.com/docs/5.2/forms/checks-radios/#switches). (#162)
* Added modal template

## 2023.10 (2023-10-2023)
* Added Django 5.0 and 4.2 support
Expand Down
13 changes: 13 additions & 0 deletions crispy_bootstrap5/templates/bootstrap5/layout/modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div id="{{ modal.css_id }}" class="modal fade {{ modal.css_class }}" {{ modal.flat_attrs }}>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title {{ modal.title_class }}" id="{{ modal.title_id }}-label">{{ modal.title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{{ fields }}
</div>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions tests/results/modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div aria-labelledby="modal_title_id-label" class="fade modal modal-class-ex" id="modal-id-ex" role="dialog"
tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal_title_id-label">
This is my modal
</h5>
<button aria-label="Close" class="btn-close" data-bs-dismiss="modal" type="button"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
InlineCheckboxes,
InlineField,
InlineRadios,
Modal,
PrependedAppendedText,
PrependedText,
StrictButton,
Expand Down Expand Up @@ -621,3 +622,17 @@ def test_switch_horizontal(self):
form.helper.form_class = "form-horizontal"
form.helper.layout = Layout(Switch("is_company"), "first_name")
assert parse_form(form) == parse_expected("test_switch_horizontal.html")

def test_modal(self):
test_form = SampleForm()
test_form.helper = FormHelper()
test_form.helper.form_tag = False
test_form.helper.layout = Layout(
Modal(
'field1',
css_id="modal-id-ex",
css_class="modal-class-ex",
title="This is my modal",
)
)
assert parse_form(test_form) == parse_expected("modal.html")

0 comments on commit 2737939

Please sign in to comment.