diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index 3b8f419..f3f6a70 100644
a
|
b
|
class Field(object):
|
50 | 50 | creation_counter = 0 |
51 | 51 | |
52 | 52 | def __init__(self, required=True, widget=None, label=None, initial=None, |
53 | | help_text=None, error_messages=None): |
| 53 | help_text=None, error_messages=None, label_attrs=None): |
54 | 54 | # required -- Boolean that specifies whether the field is required. |
55 | 55 | # True by default. |
56 | 56 | # widget -- A Widget class, or instance of a Widget class, that should |
… |
… |
class Field(object):
|
64 | 64 | # initial -- A value to use in this Field's initial display. This value |
65 | 65 | # is *not* used as a fallback if data isn't given. |
66 | 66 | # help_text -- An optional string to use as "help text" for this Field. |
| 67 | # label_attrs -- An optional dictionary to use as attributes for the |
| 68 | # label html tag. |
67 | 69 | if label is not None: |
68 | 70 | label = smart_unicode(label) |
69 | | self.required, self.label, self.initial = required, label, initial |
| 71 | self.required, self.initial = required, initial |
| 72 | self.label, self.label_attrs = label, label_attrs |
70 | 73 | self.help_text = smart_unicode(help_text or '') |
71 | 74 | widget = widget or self.widget |
72 | 75 | if isinstance(widget, type): |
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 556c00a..8d8c48a 100644
a
|
b
|
class BaseForm(StrAndUnicode):
|
124 | 124 | if self.label_suffix: |
125 | 125 | if label[-1] not in ':?.!': |
126 | 126 | label += self.label_suffix |
127 | | label = bf.label_tag(label) or '' |
| 127 | label = bf.label_tag(label, bf.label_attrs) or '' |
128 | 128 | else: |
129 | 129 | label = '' |
130 | 130 | if field.help_text: |
… |
… |
class BoundField(StrAndUnicode):
|
238 | 238 | else: |
239 | 239 | self.label = self.field.label |
240 | 240 | self.help_text = field.help_text or '' |
| 241 | self.label_attrs = self.field.label_attrs |
241 | 242 | |
242 | 243 | def __unicode__(self): |
243 | 244 | """Renders this field as an HTML widget.""" |
diff --git a/docs/newforms.txt b/docs/newforms.txt
index 19f42cb..d044884 100644
a
|
b
|
And here is a custom error message::
|
1128 | 1128 | In the `built-in Field classes`_ section below, each ``Field`` defines the |
1129 | 1129 | error message keys it uses. |
1130 | 1130 | |
| 1131 | ``label_attrs`` |
| 1132 | ~~~~~~~~~~~~~~~~~~ |
| 1133 | |
| 1134 | **New in Django development version** |
| 1135 | |
| 1136 | The ``label_attrs`` argument lets you define the extra arguments that the |
| 1137 | label tag will contain. Pass in a dictionary with keys matching the attribute |
| 1138 | you want to define. For example, here is a way to define the label's class:: |
| 1139 | |
| 1140 | >>> generic = forms.CharField(label_attrs={'class': 'large_label'}) |
| 1141 | |
| 1142 | And here is the output:: |
| 1143 | |
| 1144 | <label for="id_generic" class="large_label">Generic:</label> |
| 1145 | |
1131 | 1146 | Dynamic initial values |
1132 | 1147 | ---------------------- |
1133 | 1148 | |