diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-11-15 23:09:10 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-11-15 23:09:10 +0000 |
| commit | c4070e86c8067cbd615b6f1eb4f30098bd684da5 (patch) | |
| tree | 7293b1b35272cf3ae1e39625f0b0d4e3da74cb15 /tests/regressiontests/forms | |
| parent | 522f6740700f8bafae2845272e21da0074283809 (diff) | |
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
Diffstat (limited to 'tests/regressiontests/forms')
| -rw-r--r-- | tests/regressiontests/forms/tests.py | 55 |
1 files changed, 55 insertions, 0 deletions
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'] <input type="text" name="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() +<ul> +<li>First name: <input type="text" name="first_name" id="id_first_name" /></li> +<li>Last name: <input type="text" name="last_name" id="id_last_name" /></li> +<li>Birthday: <input type="text" name="birthday" id="id_birthday" /></li> +</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() +<ul> +<li>First name: <input type="text" name="first_name" id="first_name" /></li> +<li>Last name: <input type="text" name="last_name" id="last_name" /></li> +<li>Birthday: <input type="text" name="birthday" id="birthday" /></li> +</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() +<ul> +<li>First name: <input type="text" name="first_name" /></li> +<li>Last name: <input type="text" name="last_name" /></li> +<li>Birthday: <input type="text" name="birthday" /></li> +</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() +<ul> +<li>First name: <input type="text" id="first_name_id" name="first_name" /></li> +<li>Last name: <input type="text" name="last_name" /></li> +<li>Birthday: <input type="text" name="birthday" /></li> +</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() +<ul> +<li>First name: <input type="text" id="first_name_id" name="first_name" /></li> +<li>Last name: <input type="text" name="last_name" id="last_name" /></li> +<li>Birthday: <input type="text" name="birthday" id="birthday" /></li> +</ul> + >>> class SignupForm(Form): ... email = EmailField() ... get_spam = BooleanField() |
