Ticket #3512: html_class1.diff
File html_class1.diff, 2.5 KB (added by , 18 years ago) |
---|
-
forms.py
119 119 top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors]) 120 120 hidden_fields.append(unicode(bf)) 121 121 else: 122 if bf_errors: 123 html_class = 'error ' 124 else: 125 html_class = '' 126 if bf.field.required: 127 html_class += 'required' 122 128 if errors_on_separate_row and bf_errors: 123 129 output.append(error_row % bf_errors) 124 130 label = bf.label and bf.label_tag(escape(bf.label + ':')) or '' … … 126 132 help_text = help_text_html % field.help_text 127 133 else: 128 134 help_text = u'' 129 output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text })135 output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text, 'html_class': html_class.strip() }) 130 136 if top_errors: 131 137 output.insert(0, error_row % top_errors) 132 138 if hidden_fields: # Insert any hidden fields in the last row. … … 141 147 142 148 def as_table(self): 143 149 "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." 144 return self._html_output(u'<tr ><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)150 return self._html_output(u'<tr class="%(html_class)s"><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False) 145 151 146 152 def as_ul(self): 147 153 "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." 148 return self._html_output(u'<li >%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' %s', False)154 return self._html_output(u'<li class="%(html_class)s">%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' %s', False) 149 155 150 156 def as_p(self): 151 157 "Returns this form rendered as HTML <p>s." 152 return self._html_output(u'<p >%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True)158 return self._html_output(u'<p class="%(html_class)s">%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True) 153 159 154 160 def non_field_errors(self): 155 161 """