From c4070e86c8067cbd615b6f1eb4f30098bd684da5 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 15 Nov 2006 23:09:10 +0000 Subject: Fixed #3025 -- Added auto_id option to Form.__init__(). Thanks, SmileyChris git-svn-id: http://code.djangoproject.com/svn/django/trunk@4073 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 42596b02e0..21bd378f1f 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -973,6 +973,61 @@ u'* This field is required.' >>> print p['birthday'] +"auto_id" tells the Form to add an "id" attribute to each form element. +If it's a string that contains '%s', Django will use that as a format string +into which the field's name will be inserted. +>>> p = Person(auto_id='id_%s') +>>> print p.as_ul() + + +If auto_id is any True value whose str() does not contain '%s', the "id" +attribute will be the name of the field. +>>> p = Person(auto_id=True) +>>> print p.as_ul() + + +If auto_id is any False value, an "id" attribute won't be output unless it +was manually entered. +>>> p = Person(auto_id=False) +>>> print p.as_ul() + + +In this example, auto_id is False, but the "id" attribute for the "first_name" +field is given. +>>> class PersonNew(Form): +... first_name = CharField(widget=TextInput(attrs={'id': 'first_name_id'})) +... last_name = CharField() +... birthday = DateField() +>>> p = PersonNew(auto_id=False) +>>> print p.as_ul() + + +If the "id" attribute is specified in the Form and auto_id is True, the "id" +attribute in the Form gets precedence. +>>> p = PersonNew(auto_id=True) +>>> print p.as_ul() + + >>> class SignupForm(Form): ... email = EmailField() ... get_spam = BooleanField() -- cgit v1.3