Ticket #12466: patch_css_classes.3.diff

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

patch with extended 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...     age = IntegerField()
     1824
    18191825>>> p = Person({})
    18201826>>> p.error_css_class = 'error'
    18211827>>> p.required_css_class = 'required'
     
    18271833<option value="2">Yes</option>
    18281834<option value="3">No</option>
    18291835</select></li>
     1836<li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li>
     1837<li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></li>
    18301838
    18311839>>> print p.as_p()
    18321840<ul class="errorlist"><li>This field is required.</li></ul>
     
    18361844<option value="2">Yes</option>
    18371845<option value="3">No</option>
    18381846</select></p>
     1847<p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p>
     1848<ul class="errorlist"><li>This field is required.</li></ul>
     1849<p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>
    18391850
    18401851>>> print p.as_table()
    18411852<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>
     
    18441855<option value="2">Yes</option>
    18451856<option value="3">No</option>
    18461857</select></td></tr>
     1858<tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr>
     1859<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>
    18471860
    18481861
    18491862"""
Back to Top