From 705f8513ebf9c1fa2b73390f34b1f217f05e2958 Mon Sep 17 00:00:00 2001
From: Will Stott <willstott101@gmail.com>
Date: Thu, 18 Feb 2016 12:32:36 +0000
Subject: [PATCH] Pass extra_classes through from as_* functions.
---
django/forms/forms.py | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 7aceb90..c79bbd1 100644
a
|
b
|
def add_initial_prefix(self, field_name):
|
175 | 175 | """ |
176 | 176 | return 'initial-%s' % self.add_prefix(field_name) |
177 | 177 | |
178 | | def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row): |
| 178 | def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row, extra_classes=None): |
179 | 179 | "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()." |
180 | 180 | top_errors = self.non_field_errors() # Errors that should be displayed above all fields. |
181 | 181 | output, hidden_fields = [], [] |
… |
… |
def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_
|
194 | 194 | else: |
195 | 195 | # Create a 'class="..."' attribute if the row should have any |
196 | 196 | # CSS classes applied. |
197 | | css_classes = bf.css_classes() |
| 197 | css_classes = bf.css_classes(extra_classes=extra_classes) |
198 | 198 | if css_classes: |
199 | 199 | html_class_attr = ' class="%s"' % css_classes |
200 | 200 | |
… |
… |
def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_
|
253 | 253 | output.append(str_hidden) |
254 | 254 | return mark_safe('\n'.join(output)) |
255 | 255 | |
256 | | def as_table(self): |
| 256 | def as_table(self, extra_classes=None): |
257 | 257 | "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." |
258 | 258 | return self._html_output( |
259 | 259 | normal_row='<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', |
260 | 260 | error_row='<tr><td colspan="2">%s</td></tr>', |
261 | 261 | row_ender='</td></tr>', |
262 | 262 | help_text_html='<br /><span class="helptext">%s</span>', |
263 | | errors_on_separate_row=False) |
| 263 | errors_on_separate_row=False, |
| 264 | extra_classes=extra_classes) |
264 | 265 | |
265 | | def as_ul(self): |
| 266 | def as_ul(self, extra_classes=None): |
266 | 267 | "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." |
267 | 268 | return self._html_output( |
268 | 269 | normal_row='<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', |
269 | 270 | error_row='<li>%s</li>', |
270 | 271 | row_ender='</li>', |
271 | 272 | help_text_html=' <span class="helptext">%s</span>', |
272 | | errors_on_separate_row=False) |
| 273 | errors_on_separate_row=False, |
| 274 | extra_classes=extra_classes) |
273 | 275 | |
274 | | def as_p(self): |
| 276 | def as_p(self, extra_classes=None): |
275 | 277 | "Returns this form rendered as HTML <p>s." |
276 | 278 | return self._html_output( |
277 | 279 | normal_row='<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', |
278 | 280 | error_row='%s', |
279 | 281 | row_ender='</p>', |
280 | 282 | help_text_html=' <span class="helptext">%s</span>', |
281 | | errors_on_separate_row=True) |
| 283 | errors_on_separate_row=True, |
| 284 | extra_classes=extra_classes) |
282 | 285 | |
283 | 286 | def non_field_errors(self): |
284 | 287 | """ |