Ticket #14710: 14710_FormsCssClassRenderedInBoundField.diff
File 14710_FormsCssClassRenderedInBoundField.diff, 5.5 KB (added by , 14 years ago) |
---|
-
django/forms/forms.py
151 151 else: 152 152 # Create a 'class="..."' atribute if the row should have any 153 153 # CSS classes applied. 154 # Added to container DOM element (e.g. <li>) 154 155 css_classes = bf.css_classes() 155 156 if css_classes: 156 157 html_class_attr = ' class="%s"' % css_classes … … 432 433 else: 433 434 attrs['id'] = self.html_initial_id 434 435 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 435 443 if not self.form.is_bound: 436 444 data = self.form.initial.get(self.name, self.field.initial) 437 445 if callable(data): -
tests/regressiontests/forms/tests/forms.py
1672 1672 p.error_css_class = 'error' 1673 1673 p.required_css_class = 'required' 1674 1674 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"> 1677 1678 <option value="1" selected="selected">Unknown</option> 1678 1679 <option value="2">Yes</option> 1679 1680 <option value="3">No</option> 1680 1681 </select></li> 1681 1682 <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>""") 1683 1684 1684 1685 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"> 1687 1688 <option value="1" selected="selected">Unknown</option> 1688 1689 <option value="2">Yes</option> 1689 1690 <option value="3">No</option> 1690 1691 </select></p> 1691 1692 <p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p> 1692 1693 <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>""") 1694 1695 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"> 1697 1698 <option value="1" selected="selected">Unknown</option> 1698 1699 <option value="2">Yes</option> 1699 1700 <option value="3">No</option> 1700 1701 </select></td></tr> 1701 1702 <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>""") 1703 1704 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 1704 1708 def test_label_split_datetime_not_displayed(self): 1705 1709 class EventForm(Form): 1706 1710 happened_at = SplitDateTimeField(widget=widgets.SplitHiddenDateTimeWidget)