diff --git a/src/django_bootstrap5/renderers.py b/src/django_bootstrap5/renderers.py index 0a3f2d95..dd05fcef 100644 --- a/src/django_bootstrap5/renderers.py +++ b/src/django_bootstrap5/renderers.py @@ -302,7 +302,7 @@ def add_widget_class_attrs(self, widget=None): size_prefix = None before = [] - classes = [widget.attrs.get("class", "")] + classes = [widget.attrs.get("class", ""), text_value(self.field_class)] if ReadOnlyPasswordHashWidget is not None and isinstance(widget, ReadOnlyPasswordHashWidget): before.append("form-control-static") diff --git a/tests/test_bootstrap_field.py b/tests/test_bootstrap_field.py index 39432fa2..bf5de1e2 100644 --- a/tests/test_bootstrap_field.py +++ b/tests/test_bootstrap_field.py @@ -33,6 +33,10 @@ def test_placeholder(self): self.assertIn('type="text"', html) self.assertIn('placeholder="placeholdertest"', html) + def test_field_class(self): + html = self.render("{% bootstrap_field form.subject field_class='field-class-test' %}", {"form": SubjectTestForm()}) + self.assertIn('class="form-control field-class-test"', html) + def test_xss_field(self): html = self.render("{% bootstrap_field form.xss_field %}", {"form": XssTestForm()}) self.assertIn('type="text"', html)