From cf75fcc8321b822cb4758d167f1fade56a60ad4f Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 28 Jan 2007 22:10:04 +0000 Subject: Fixed #3255 -- Added help_text argument to newforms Field class. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4440 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 5c9c1ed813..20a1937f56 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -2610,6 +2610,41 @@ then the latter will get precedence.
  • Username:
  • Password:
  • +# Help text ################################################################### + +You can specify descriptive text for a field by using the 'help_text' argument +to a Field class. This help text is displayed when a Form is rendered. +>>> class UserRegistration(Form): +... username = CharField(max_length=10, help_text='e.g., user@example.com') +... password = CharField(widget=PasswordInput, help_text='Choose wisely.') +>>> p = UserRegistration(auto_id=False) +>>> print p.as_ul() +
  • Username: e.g., user@example.com
  • +
  • Password: Choose wisely.
  • +>>> print p.as_p() +

    Username: e.g., user@example.com

    +

    Password: Choose wisely.

    +>>> print p.as_table() +Username:
    e.g., user@example.com +Password:
    Choose wisely. + +The help text is displayed whether or not data is provided for the form. +>>> p = UserRegistration({'username': u'foo'}, auto_id=False) +>>> print p.as_ul() +
  • Username: e.g., user@example.com
  • +
  • Password: Choose wisely.
  • + +help_text is not displayed for hidden fields. It can be used for documentation +purposes, though. +>>> class UserRegistration(Form): +... username = CharField(max_length=10, help_text='e.g., user@example.com') +... password = CharField(widget=PasswordInput) +... next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination') +>>> p = UserRegistration(auto_id=False) +>>> print p.as_ul() +
  • Username: e.g., user@example.com
  • +
  • Password:
  • + # Forms with prefixes ######################################################### Sometimes it's necessary to have multiple forms display on the same HTML page, -- cgit v1.3