From e130031fd2e1fa6946e56c73efab0c3ac67ebaea Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Thu, 30 Nov 2006 17:07:40 +0000 Subject: Fixed #3082 -- newforms: Changed Form as_table() and as_ul() not to display verbose names for hidden fields, and to add field-name prefix to error messages to avoid user confusion. Also added unit tests. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4146 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index bfa9d07237..2fb468ace2 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1689,6 +1689,56 @@ subclass' __init__(). Last name: Birthday: +HiddenInput widgets are displayed differently in the as_table() and as_ul() +output of a Form -- their verbose names are not displayed, and a separate +/
  • is not displayed. +>>> class Person(Form): +... first_name = CharField() +... last_name = CharField() +... hidden_text = CharField(widget=HiddenInput) +... birthday = DateField() +>>> p = Person() +>>> print p +First name: +Last name: + +Birthday: +>>> print p.as_ul() +
  • First name:
  • +
  • Last name:
  • + +
  • Birthday:
  • + +With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label. +>>> p = Person(auto_id='id_%s') +>>> print p + + + + +>>> print p.as_ul() +
  • +
  • + +
  • + +If a field with a HiddenInput has errors, the as_table() and as_ul() output +will include the error message(s) with the text "(Hidden field [fieldname]) " +prepended. +>>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}) +>>> print p +First name: +Last name: + + +Birthday: +>>> print p.as_ul() +
  • First name:
  • +
  • Last name:
  • +
  • + +
  • Birthday:
  • + A Form's fields are displayed in the same order in which they were defined. >>> class TestForm(Form): ... field1 = CharField() -- cgit v1.3