Ticket #14710: 14710_FormsCssClassRenderedInBoundField.diff

File 14710_FormsCssClassRenderedInBoundField.diff, 5.5 KB (added by Robert Lujo, 14 years ago)

Patch to forms css class rendered for BoundField

  • django/forms/forms.py

     
    151151            else:
    152152                # Create a 'class="..."' atribute if the row should have any
    153153                # CSS classes applied.
     154                # Added to container DOM element (e.g. <li>)
    154155                css_classes = bf.css_classes()
    155156                if css_classes:
    156157                    html_class_attr = ' class="%s"' % css_classes
     
    432433            else:
    433434                attrs['id'] = self.html_initial_id
    434435
     436        # Create a 'class="..."' atribute if the row should have any
     437        # CSS classes applied.
     438        # Added to entry DOM element (e.g. <input>)
     439        css_classes = self.css_classes(attrs.get("class", None))
     440        if css_classes:
     441            attrs["class"]=css_classes
     442
    435443        if not self.form.is_bound:
    436444            data = self.form.initial.get(self.name, self.field.initial)
    437445            if callable(data):
  • tests/regressiontests/forms/tests/forms.py

     
    16721672        p.error_css_class = 'error'
    16731673        p.required_css_class = 'required'
    16741674
    1675         self.assertEqual(p.as_ul(), """<li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></li>
    1676 <li class="required"><label for="id_is_cool">Is cool:</label> <select name="is_cool" id="id_is_cool">
     1675<input type="text" name="name" id="id_name" />
     1676        self.assertEqual(p.as_ul(), """<li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_name">Name:</label> <input class="required error" type="text" name="name" id="id_name" /></li>
     1677<li class="required"><label for="id_is_cool">Is cool:</label> <select class="required" name="is_cool" id="id_is_cool">
    16771678<option value="1" selected="selected">Unknown</option>
    16781679<option value="2">Yes</option>
    16791680<option value="3">No</option>
    16801681</select></li>
    16811682<li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li>
    1682 <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>""")
     1683<li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input class="required error" type="text" name="age" id="id_age" /></li>""")
    16831684
    16841685        self.assertEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul>
    1685 <p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
    1686 <p class="required"><label for="id_is_cool">Is cool:</label> <select name="is_cool" id="id_is_cool">
     1686<p class="required error"><label for="id_name">Name:</label> <input class="required error" type="text" name="name" id="id_name" /></p>
     1687<p class="required"><label for="id_is_cool">Is cool:</label> <select class="required" name="is_cool" id="id_is_cool">
    16871688<option value="1" selected="selected">Unknown</option>
    16881689<option value="2">Yes</option>
    16891690<option value="3">No</option>
    16901691</select></p>
    16911692<p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p>
    16921693<ul class="errorlist"><li>This field is required.</li></ul>
    1693 <p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>""")
     1694<p class="required error"><label for="id_age">Age:</label> <input class="required error" type="text" name="age" id="id_age" /></p>""")
    16941695
    1695         self.assertEqual(p.as_table(), """<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>
    1696 <tr class="required"><th><label for="id_is_cool">Is cool:</label></th><td><select name="is_cool" id="id_is_cool">
     1696        self.assertEqual(p.as_table(), """<tr class="required error"><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input class="required error" type="text" name="name" id="id_name" /></td></tr>
     1697<tr class="required"><th><label for="id_is_cool">Is cool:</label></th><td><select class="required" name="is_cool" id="id_is_cool">
    16971698<option value="1" selected="selected">Unknown</option>
    16981699<option value="2">Yes</option>
    16991700<option value="3">No</option>
    17001701</select></td></tr>
    17011702<tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr>
    1702 <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>""")
     1703<tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input class="required error" type="text" name="age" id="id_age" /></td></tr>""")
    17031704
     1705        # render one bound field - case http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fields
     1706        self.assertEqual(unicode(p["name"]), '<input class="required error" type="text" name="name" id="id_name" />')
     1707
    17041708    def test_label_split_datetime_not_displayed(self):
    17051709        class EventForm(Form):
    17061710            happened_at = SplitDateTimeField(widget=widgets.SplitHiddenDateTimeWidget)
Back to Top