Ticket #12466: patch_css_classes.2.diff

File patch_css_classes.2.diff, 2.2 KB (added by Bernd Schlapsi <brot@…>, 15 years ago)

patch, now with a test

  • django/forms/forms.py

     
    137137        "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
    138138        top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
    139139        output, hidden_fields = [], []
    140         html_class_attr = ''
    141140
    142141        for name, field in self.fields.items():
     142            html_class_attr = ''
    143143            bf = BoundField(self, field, name)
    144144            bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
    145145            if bf.is_hidden:
  • tests/regressiontests/forms/forms.py

     
    18161816
    18171817# The error_html_class and required_html_class attributes ####################
    18181818
     1819>>> class Person(Form):
     1820...     name = CharField()
     1821...     is_cool = NullBooleanField()
     1822...     email = EmailField(required=False)
     1823
    18191824>>> p = Person({})
    18201825>>> p.error_css_class = 'error'
    18211826>>> p.required_css_class = 'required'
     
    18271832<option value="2">Yes</option>
    18281833<option value="3">No</option>
    18291834</select></li>
     1835<li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li>
    18301836
    18311837>>> print p.as_p()
    18321838<ul class="errorlist"><li>This field is required.</li></ul>
     
    18361842<option value="2">Yes</option>
    18371843<option value="3">No</option>
    18381844</select></p>
     1845<p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p>
    18391846
    18401847>>> print p.as_table()
    18411848<tr class="required error"><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="name" id="id_name" /></td></tr>
     
    18441851<option value="2">Yes</option>
    18451852<option value="3">No</option>
    18461853</select></td></tr>
     1854<tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr>
    18471855
    18481856
    18491857"""
Back to Top