Ticket #8426: wrap_help_text_in_css_class-with_tests-r10116.diff
File wrap_help_text_in_css_class-with_tests-r10116.diff, 8.2 KB (added by , 16 years ago) |
---|
-
django/forms/forms.py
187 187 188 188 def as_table(self): 189 189 "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." 190 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)190 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 /><span class="helptext">%s</span>', False) 191 191 192 192 def as_ul(self): 193 193 "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." 194 return self._html_output(u'<li>%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' %s', False)194 return self._html_output(u'<li>%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' <span class="helptext">%s</span>', False) 195 195 196 196 def as_p(self): 197 197 "Returns this form rendered as HTML <p>s." 198 return self._html_output(u'<p>%(label)s %(field)s%(help_text)s</p>', u'%s', '</p>', u' %s', True)198 return self._html_output(u'<p>%(label)s %(field)s%(help_text)s</p>', u'%s', '</p>', u' <span class="helptext">%s</span>', True) 199 199 200 200 def non_field_errors(self): 201 201 """ -
tests/modeltests/model_forms/models.py
486 486 <option value="1">Entertainment</option> 487 487 <option value="2">It's a test</option> 488 488 <option value="3">Third test</option> 489 </select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>489 </select><br /><span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></td></tr> 490 490 491 491 You can restrict a form to a subset of the complete list of fields 492 492 by providing a 'fields' argument. If you try to save a … … 511 511 ... model = Writer 512 512 >>> f = RoykoForm(auto_id=False, instance=w) 513 513 >>> print f 514 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /> Use both first and last names.</td></tr>514 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /><span class="helptext">Use both first and last names.</span></td></tr> 515 515 516 516 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 517 517 >>> art.save() … … 541 541 <option value="1">Entertainment</option> 542 542 <option value="2">It's a test</option> 543 543 <option value="3">Third test</option> 544 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>544 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 545 545 >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art) 546 546 >>> f.is_valid() 547 547 True … … 602 602 <option value="1" selected="selected">Entertainment</option> 603 603 <option value="2">It's a test</option> 604 604 <option value="3">Third test</option> 605 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>605 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 606 606 607 607 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', 608 608 ... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) … … 718 718 <option value="1">Entertainment</option> 719 719 <option value="2">It's a test</option> 720 720 <option value="3">Third</option> 721 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>721 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 722 722 >>> Category.objects.create(name='Fourth', url='4th') 723 723 <Category: Fourth> 724 724 >>> Writer.objects.create(name='Carl Bernstein') … … 745 745 <option value="2">It's a test</option> 746 746 <option value="3">Third</option> 747 747 <option value="4">Fourth</option> 748 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>748 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 749 749 750 750 # ModelChoiceField ############################################################ 751 751 -
tests/regressiontests/forms/forms.py
1205 1205 ... password = CharField(widget=PasswordInput, help_text='Choose wisely.') 1206 1206 >>> p = UserRegistration(auto_id=False) 1207 1207 >>> print p.as_ul() 1208 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>1209 <li>Password: <input type="password" name="password" /> Choose wisely.</li>1208 <li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></li> 1209 <li>Password: <input type="password" name="password" /> <span class="helptext">Choose wisely.</span></li> 1210 1210 >>> print p.as_p() 1211 <p>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>1212 <p>Password: <input type="password" name="password" /> Choose wisely.</p>1211 <p>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></p> 1212 <p>Password: <input type="password" name="password" /> <span class="helptext">Choose wisely.</span></p> 1213 1213 >>> print p.as_table() 1214 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br /> e.g., user@example.com</td></tr>1215 <tr><th>Password:</th><td><input type="password" name="password" /><br /> Choose wisely.</td></tr>1214 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br /><span class="helptext">e.g., user@example.com</span></td></tr> 1215 <tr><th>Password:</th><td><input type="password" name="password" /><br /><span class="helptext">Choose wisely.</span></td></tr> 1216 1216 1217 1217 The help text is displayed whether or not data is provided for the form. 1218 1218 >>> p = UserRegistration({'username': u'foo'}, auto_id=False) 1219 1219 >>> print p.as_ul() 1220 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>1221 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> Choose wisely.</li>1220 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></li> 1221 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> <span class="helptext">Choose wisely.</span></li> 1222 1222 1223 1223 help_text is not displayed for hidden fields. It can be used for documentation 1224 1224 purposes, though. … … 1228 1228 ... next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination') 1229 1229 >>> p = UserRegistration(auto_id=False) 1230 1230 >>> print p.as_ul() 1231 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>1231 <li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></li> 1232 1232 <li>Password: <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li> 1233 1233 1234 1234 Help text can include arbitrary Unicode characters. … … 1236 1236 ... username = CharField(max_length=10, help_text='ŠĐĆŽćžšđ') 1237 1237 >>> p = UserRegistration(auto_id=False) 1238 1238 >>> p.as_ul() 1239 u'<li>Username: <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'1239 u'<li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</span></li>' 1240 1240 1241 1241 # Subclassing forms ########################################################### 1242 1242