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 rpbarlow, 6 years ago)

Here's an updated patch.

  • django/forms/forms.py

     
    212212            normal_row = u'<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
    213213            error_row = u'<tr><td colspan="2">%s</td></tr>',
    214214            row_ender = u'</td></tr>',
    215             help_text_html = u'<br />%s',
     215            help_text_html = u'<br /><span class="helptext">%s</span>',
    216216            errors_on_separate_row = False)
    217217
    218218    def as_ul(self):
     
    221221            normal_row = u'<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>',
    222222            error_row = u'<li>%s</li>',
    223223            row_ender = '</li>',
    224             help_text_html = u' %s',
     224            help_text_html = u' <span class="helptext">%s</span>',
    225225            errors_on_separate_row = False)
    226226
    227227    def as_p(self):
     
    230230            normal_row = u'<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>',
    231231            error_row = u'%s',
    232232            row_ender = '</p>',
    233             help_text_html = u' %s',
     233            help_text_html = u' <span class="helptext">%s</span>',
    234234            errors_on_separate_row = True)
    235235
    236236    def non_field_errors(self):
  • tests/modeltests/model_forms/models.py

     
    498498<option value="1">Entertainment</option>
    499499<option value="2">It&#39;s a test</option>
    500500<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>
    502502
    503503You can restrict a form to a subset of the complete list of fields
    504504by providing a 'fields' argument. If you try to save a
     
    523523...         model = Writer
    524524>>> f = RoykoForm(auto_id=False, instance=w)
    525525>>> 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>
    527527
    528528>>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
    529529>>> art.save()
     
    553553<option value="1">Entertainment</option>
    554554<option value="2">It&#39;s a test</option>
    555555<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>
    557557>>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art)
    558558>>> f.is_valid()
    559559True
     
    614614<option value="1" selected="selected">Entertainment</option>
    615615<option value="2">It&#39;s a test</option>
    616616<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>
    618618
    619619Initial values can be provided for model forms
    620620>>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': ['1','2']})
     
    638638<option value="1" selected="selected">Entertainment</option>
    639639<option value="2" selected="selected">It&#39;s a test</option>
    640640<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>
    642642
    643643>>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
    644644...     'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art)
     
    754754<option value="1">Entertainment</option>
    755755<option value="2">It&#39;s a test</option>
    756756<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>
    758758>>> Category.objects.create(name='Fourth', url='4th')
    759759<Category: Fourth>
    760760>>> Writer.objects.create(name='Carl Bernstein')
     
    781781<option value="2">It&#39;s a test</option>
    782782<option value="3">Third</option>
    783783<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>
    785785
    786786# ModelChoiceField ############################################################
    787787
  • tests/regressiontests/model_forms_regress/tests.py

     
    8787<option value="1" selected="selected">First Book</option>
    8888<option value="2" selected="selected">Second Book</option>
    8989<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>""")
    9191
    9292class CFFForm(forms.ModelForm):
    9393    class Meta:
  • tests/regressiontests/forms/forms.py

     
    12431243...    password = CharField(widget=PasswordInput, help_text='Choose wisely.')
    12441244>>> p = UserRegistration(auto_id=False)
    12451245>>> 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>
    12481248>>> 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>
    12511251>>> 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>
    12541254
    12551255The help text is displayed whether or not data is provided for the form.
    12561256>>> p = UserRegistration({'username': u'foo'}, auto_id=False)
    12571257>>> 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>
    12601260
    12611261help_text is not displayed for hidden fields. It can be used for documentation
    12621262purposes, though.
     
    12661266...    next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination')
    12671267>>> p = UserRegistration(auto_id=False)
    12681268>>> 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>
    12701270<li>Password: <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li>
    12711271
    12721272Help text can include arbitrary Unicode characters.
     
    12741274...    username = CharField(max_length=10, help_text='ŠĐĆŽćžšđ')
    12751275>>> p = UserRegistration(auto_id=False)
    12761276>>> p.as_ul()
    1277 u'<li>Username: <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'
     1277u'<li>Username: <input type="text" name="username" maxlength="10" /> <span class="helptext">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</span></li>'
    12781278
    12791279# Subclassing forms ###########################################################
    12801280
Back to Top