1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #17922 -- Added required_css_class to form label.

Thanks hanson2010 for the suggestion.
This commit is contained in:
Anubhav Joshi
2014-03-03 23:29:03 +05:30
committed by Tim Graham
parent 2ec82c7387
commit 416a858023
4 changed files with 50 additions and 12 deletions

View File

@@ -621,6 +621,12 @@ class BoundField(object):
id_for_label = widget.id_for_label(id_)
if id_for_label:
attrs = dict(attrs or {}, **{'for': id_for_label})
if self.field.required and hasattr(self.form, 'required_css_class'):
attrs = attrs or {}
if 'class' in attrs:
attrs['class'] += ' ' + self.form.required_css_class
else:
attrs['class'] = self.form.required_css_class
attrs = flatatt(attrs) if attrs else ''
contents = format_html('<label{0}>{1}</label>', attrs, contents)
else: