﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35521	Allow overriding BoundField class on forms and fields	Matthias Kestenholz	Matthias Kestenholz	"It would be useful if there was an easy way to add CSS classes to the HTML element which is generated when rendering a `BoundField`. I propose adding `field_css_class`, similar to `required_css_class` and `error_css_class`. https://docs.djangoproject.com/en/5.0/ref/forms/api/#styling-required-or-erroneous-form-rows

Something like this has already been rejected in the past here: https://code.djangoproject.com/ticket/29189 . As I understand it the reason for the rejection was the upcoming templates-based form rendering and not really the feature itself. I may have missed the point though.

However, I still think there'd be some value in this even though we have templates-based renderers now. The `div` (in the case of the div renderer) is generated here: https://github.com/django/django/blob/main/django/forms/templates/django/forms/div.html , so it's not just about overriding `django/forms/field.html` if you want to avoid adding another nesting level. Also, `css_classes` exists and is documented.

Code-wise I propose extending the `css_classes` method as follows:

https://github.com/django/django/blob/e2428292abaca4758a7508175d31667fe2dff57c/django/forms/boundfield.py#L220-L231

{{{
         extra_classes = set(extra_classes or [])
+        if hasattr(self.form, ""field_css_class""):
+            extra_classes.add(self.form.field_css_class)
         if self.errors and hasattr(self.form, ""error_css_class""):
}}}

I'm willing to do the work if this is accepted. "	New feature	closed	Forms	dev	Normal	fixed		David Smith Oxan van Leeuwen Christophe Henry Carlton Gibson	Ready for checkin	1	0	0	0	0	0
