Skip to content

Commit

Permalink
Add "input_class" argument to "bootstrap_field (zostera#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Frolenkov committed Nov 1, 2023
1 parent f4fef7e commit b95aab5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Drop support for Python 3.7 in test matrix (#533).
- Fix support for Django 4.2 in test matrix (#533).
- Pass "horizontal_field_offset_class" to child renderers (#391, #521).
- Add "input_class" argument to "bootstrap_field (#525)".

## 23.3 (2023-06-03)

Expand Down
4 changes: 3 additions & 1 deletion src/django_bootstrap5/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def __init__(self, field, **kwargs):
else success_css_class
)

self.input_class = kwargs.get("input_class", "")

@property
def is_floating(self):
return (
Expand Down Expand Up @@ -302,7 +304,7 @@ def add_widget_class_attrs(self, widget=None):
size_prefix = None

before = []
classes = [widget.attrs.get("class", "")]
classes = [widget.attrs.get("class", ""), self.input_class]

if ReadOnlyPasswordHashWidget is not None and isinstance(widget, ReadOnlyPasswordHashWidget):
before.append("form-control-static")
Expand Down
5 changes: 5 additions & 0 deletions src/django_bootstrap5/templatetags/django_bootstrap5.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ def bootstrap_field(field, **kwargs):
:default: ``'has-success'``. Can be changed :doc:`settings`
input_class
CSS class added to the input html element
:default: ``''``
**Usage**::
{% bootstrap_field field %}
Expand Down
6 changes: 6 additions & 0 deletions tests/test_bootstrap_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def _test_size_medium(param):
_test_size_medium("md")
_test_size_medium("")

def test_input_class(self):
self.assertIn(
'class="form-control foobar-class"',
self.render('{% bootstrap_field form.subject input_class="foobar-class" %}', {"form": SubjectTestForm()}),
)

def test_label(self):
self.assertEqual(
self.render('{% bootstrap_label "foobar" label_for="subject" %}'),
Expand Down

0 comments on commit b95aab5

Please sign in to comment.