Ticket #8426: wrap_help_text_in_css_class-with_tests.diff
File wrap_help_text_in_css_class-with_tests.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
431 431 <option value="1">Entertainment</option> 432 432 <option value="2">It's a test</option> 433 433 <option value="3">Third test</option> 434 </select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>434 </select><br /><span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></td></tr> 435 435 436 436 You can restrict a form to a subset of the complete list of fields 437 437 by providing a 'fields' argument. If you try to save a … … 456 456 ... model = Writer 457 457 >>> f = RoykoForm(auto_id=False, instance=w) 458 458 >>> print f 459 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /> Use both first and last names.</td></tr>459 <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> 460 460 461 461 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 462 462 >>> art.save() … … 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> Hold down "Control", or "Command" on a Mac, to select more than one.</li>489 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 490 490 >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art) 491 491 >>> f.is_valid() 492 492 True … … 547 547 <option value="1" selected="selected">Entertainment</option> 548 548 <option value="2">It's a test</option> 549 549 <option value="3">Third test</option> 550 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>550 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 551 551 552 552 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', 553 553 ... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) … … 663 663 <option value="1">Entertainment</option> 664 664 <option value="2">It's a test</option> 665 665 <option value="3">Third</option> 666 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>666 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 667 667 >>> Category.objects.create(name='Fourth', url='4th') 668 668 <Category: Fourth> 669 669 >>> Writer.objects.create(name='Carl Bernstein') … … 690 690 <option value="2">It's a test</option> 691 691 <option value="3">Third</option> 692 692 <option value="4">Fourth</option> 693 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>693 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 694 694 695 695 # ModelChoiceField ############################################################ 696 696 -
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