Ticket #8426: wrap_help_text_in_css_class-with_tests-r11855.diff
File wrap_help_text_in_css_class-with_tests-r11855.diff, 9.3 KB (added by , 15 years ago) |
---|
-
django/forms/forms.py
212 212 normal_row = u'<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', 213 213 error_row = u'<tr><td colspan="2">%s</td></tr>', 214 214 row_ender = u'</td></tr>', 215 help_text_html = u'<br /> %s',215 help_text_html = u'<br /><span class="helptext">%s</span>', 216 216 errors_on_separate_row = False) 217 217 218 218 def as_ul(self): … … 221 221 normal_row = u'<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', 222 222 error_row = u'<li>%s</li>', 223 223 row_ender = '</li>', 224 help_text_html = u' %s',224 help_text_html = u' <span class="helptext">%s</span>', 225 225 errors_on_separate_row = False) 226 226 227 227 def as_p(self): … … 230 230 normal_row = u'<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', 231 231 error_row = u'%s', 232 232 row_ender = '</p>', 233 help_text_html = u' %s',233 help_text_html = u' <span class="helptext">%s</span>', 234 234 errors_on_separate_row = True) 235 235 236 236 def non_field_errors(self): -
tests/modeltests/model_forms/models.py
498 498 <option value="1">Entertainment</option> 499 499 <option value="2">It's a test</option> 500 500 <option value="3">Third test</option> 501 </select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>501 </select><br /><span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></td></tr> 502 502 503 503 You can restrict a form to a subset of the complete list of fields 504 504 by providing a 'fields' argument. If you try to save a … … 523 523 ... model = Writer 524 524 >>> f = RoykoForm(auto_id=False, instance=w) 525 525 >>> print f 526 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /> Use both first and last names.</td></tr>526 <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> 527 527 528 528 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 529 529 >>> art.save() … … 553 553 <option value="1">Entertainment</option> 554 554 <option value="2">It's a test</option> 555 555 <option value="3">Third test</option> 556 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>556 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 557 557 >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art) 558 558 >>> f.is_valid() 559 559 True … … 614 614 <option value="1" selected="selected">Entertainment</option> 615 615 <option value="2">It's a test</option> 616 616 <option value="3">Third test</option> 617 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>617 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 618 618 619 619 Initial values can be provided for model forms 620 620 >>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': ['1','2']}) … … 638 638 <option value="1" selected="selected">Entertainment</option> 639 639 <option value="2" selected="selected">It's a test</option> 640 640 <option value="3">Third test</option> 641 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>641 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 642 642 643 643 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', 644 644 ... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) … … 754 754 <option value="1">Entertainment</option> 755 755 <option value="2">It's a test</option> 756 756 <option value="3">Third</option> 757 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>757 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 758 758 >>> Category.objects.create(name='Fourth', url='4th') 759 759 <Category: Fourth> 760 760 >>> Writer.objects.create(name='Carl Bernstein') … … 781 781 <option value="2">It's a test</option> 782 782 <option value="3">Third</option> 783 783 <option value="4">Fourth</option> 784 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>784 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> 785 785 786 786 # ModelChoiceField ############################################################ 787 787 -
tests/regressiontests/model_forms_regress/tests.py
87 87 <option value="1" selected="selected">First Book</option> 88 88 <option value="2" selected="selected">Second Book</option> 89 89 <option value="3">Third Book</option> 90 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>""")90 </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li>""") 91 91 92 92 class CFFForm(forms.ModelForm): 93 93 class Meta: -
tests/regressiontests/forms/forms.py
1243 1243 ... password = CharField(widget=PasswordInput, help_text='Choose wisely.') 1244 1244 >>> p = UserRegistration(auto_id=False) 1245 1245 >>> print p.as_ul() 1246 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>1247 <li>Password: <input type="password" name="password" /> Choose wisely.</li>1246 <li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></li> 1247 <li>Password: <input type="password" name="password" /> <span class="helptext">Choose wisely.</span></li> 1248 1248 >>> print p.as_p() 1249 <p>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>1250 <p>Password: <input type="password" name="password" /> Choose wisely.</p>1249 <p>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></p> 1250 <p>Password: <input type="password" name="password" /> <span class="helptext">Choose wisely.</span></p> 1251 1251 >>> print p.as_table() 1252 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br /> e.g., user@example.com</td></tr>1253 <tr><th>Password:</th><td><input type="password" name="password" /><br /> Choose wisely.</td></tr>1252 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br /><span class="helptext">e.g., user@example.com</span></td></tr> 1253 <tr><th>Password:</th><td><input type="password" name="password" /><br /><span class="helptext">Choose wisely.</span></td></tr> 1254 1254 1255 1255 The help text is displayed whether or not data is provided for the form. 1256 1256 >>> p = UserRegistration({'username': u'foo'}, auto_id=False) 1257 1257 >>> print p.as_ul() 1258 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>1259 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> Choose wisely.</li>1258 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></li> 1259 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> <span class="helptext">Choose wisely.</span></li> 1260 1260 1261 1261 help_text is not displayed for hidden fields. It can be used for documentation 1262 1262 purposes, though. … … 1266 1266 ... next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination') 1267 1267 >>> p = UserRegistration(auto_id=False) 1268 1268 >>> print p.as_ul() 1269 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>1269 <li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">e.g., user@example.com</span></li> 1270 1270 <li>Password: <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li> 1271 1271 1272 1272 Help text can include arbitrary Unicode characters. … … 1274 1274 ... username = CharField(max_length=10, help_text='ŠĐĆŽćžšđ') 1275 1275 >>> p = UserRegistration(auto_id=False) 1276 1276 >>> p.as_ul() 1277 u'<li>Username: <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'1277 u'<li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</span></li>' 1278 1278 1279 1279 # Subclassing forms ########################################################### 1280 1280