-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for horizontal forms (#40)
- Loading branch information
Showing
7 changed files
with
151 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django import forms | ||
from django.test import TestCase | ||
|
||
from .base import render_template_with_bootstrap | ||
|
||
|
||
class BootstrapFieldTest(TestCase): | ||
def test_bootstrap_field_text_floating(self): | ||
"""Test field with text widget in floating layout.""" | ||
|
||
class TestForm(forms.Form): | ||
test = forms.CharField() | ||
|
||
test_form = TestForm() | ||
html = render_template_with_bootstrap( | ||
"{% bootstrap_field form.test layout='floating' %}", context={"form": test_form} | ||
) | ||
self.assertHTMLEqual( | ||
html, | ||
( | ||
'<div class="django_bootstrap5-req mb-3 form-floating">' | ||
'<input class="form-control" id="id_test" name="test" placeholder="Test" required type="text">' | ||
'<label for="id_test" class="form-label">Test</label>' | ||
"</div>" | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django import forms | ||
from django.test import TestCase | ||
|
||
from .base import render_template_with_bootstrap | ||
|
||
|
||
class BootstrapHorizontalFieldTest(TestCase): | ||
def test_bootstrap_field_text_horizontal(self): | ||
"""Test field with text widget.""" | ||
|
||
class TestForm(forms.Form): | ||
test = forms.CharField() | ||
|
||
test_form = TestForm() | ||
html = render_template_with_bootstrap( | ||
"{% bootstrap_field form.test layout='horizontal' %}", context={"form": test_form} | ||
) | ||
self.assertHTMLEqual( | ||
html, | ||
( | ||
'<div class="django_bootstrap5-req mb-3 row">' | ||
'<label class="col-form-label col-sm-2" for="id_test">' | ||
"Test" | ||
'</label><div class="col-sm-10">' | ||
'<input class="form-control" id="id_test" name="test" placeholder="Test" required type="text">' | ||
"</div>" | ||
"</div>" | ||
), | ||
) | ||
|
||
def test_bootstrap_field_checkbox_horizontal(self): | ||
"""Test field with text widget.""" | ||
|
||
class TestForm(forms.Form): | ||
test = forms.BooleanField() | ||
|
||
test_form = TestForm() | ||
html = render_template_with_bootstrap( | ||
"{% bootstrap_field form.test layout='horizontal' %}", context={"form": test_form} | ||
) | ||
self.assertHTMLEqual( | ||
html, | ||
( | ||
'<div class="django_bootstrap5-req mb-3 row">' | ||
'<div class="col-sm-10 offset-sm-2">' | ||
'<div class="form-check">' | ||
'<input class="form-check-input" id="id_test" name="test" required type="checkbox">' | ||
'<label class="form-check-label" for="id_test">' | ||
"Test" | ||
"</label>" | ||
"</div>" | ||
), | ||
) |