Ticket #13564: 13564_form_get_field_css_classes.diff
| File 13564_form_get_field_css_classes.diff, 5.6 KB (added by , 16 years ago) |
|---|
-
django/forms/forms.py
135 135 """ 136 136 return u'initial-%s' % self.add_prefix(field_name) 137 137 138 139 140 141 142 143 144 145 146 147 148 149 150 138 151 def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row): 139 152 "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()." 140 153 top_errors = self.non_field_errors() # Errors that should be displayed above all fields. … … 497 510 extra_classes.add(self.form.error_css_class) 498 511 if self.field.required and hasattr(self.form, 'required_css_class'): 499 512 extra_classes.add(self.form.required_css_class) 513 500 514 return ' '.join(extra_classes) 501 515 502 516 def _is_hidden(self): -
tests/regressiontests/forms/forms.py
1885 1885 <tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr> 1886 1886 <tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="age" id="id_age" /></td></tr> 1887 1887 1888 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1889 1905 1906 1907 1908 1909 1910 1911 1912 1913 1890 1914 # Checking that the label for SplitDateTimeField is not being displayed ##### 1891 1915 1892 1916 >>> class EventForm(Form): -
docs/ref/forms/api.txt
386 386 errors. For example, you might want to present required form rows in bold and 387 387 highlight errors in red. 388 388 389 390 391 392 393 389 394 The :class:`Form` class has a couple of hooks you can use to add ``class`` 390 395 attributes to required rows or to rows with errors: simple set the 391 396 :attr:`Form.error_css_class` and/or :attr:`Form.required_css_class` 392 attributes ::397 attributes:: 393 398 394 399 class ContactForm(Form): 395 400 error_css_class = 'error' 396 401 required_css_class = 'required' 397 402 403 404 405 406 407 408 409 410 398 411 # ... and the rest of your fields here 399 412 400 Once you've done that, rows will be given ``"error"`` and/or ``"required"``401 classes, as needed. The HTML will look something like::413 Once you've done that, rows will be given 414 d. The HTML will look something like:: 402 415 403 416 >>> f = ContactForm(data) 404 417 >>> print f.as_table() 405 <tr class=" required"><th><label for="id_subject">Subject:</label> ...406 <tr class=" required"><th><label for="id_message">Message:</label> ...407 <tr class=" required error"><th><label for="id_sender">Sender:</label> ...408 <tr ><th><label for="id_cc_myself">Cc myself:<label> ...418 <tr class=""><th><label for="id_subject">Subject:</label> ... 419 <tr class=""><th><label for="id_message">Message:</label> ... 420 <tr class="required error"><th><label for="id_sender">Sender:</label> ... 421 <trlabel> ... 409 422 410 423 .. _ref-forms-api-configuring-label: 411 424