Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added small newforms unit test

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4551 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5bec651a61ac9ba2831850104060833b37403399 1 parent 97256bc
Adrian Holovaty adrianholovaty authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 tests/regressiontests/forms/tests.py
13 tests/regressiontests/forms/tests.py
View
@@ -2011,6 +2011,19 @@
<option value="J">Java</option>
</select>
+A subtlety: If one of the choices' value is the empty string and the form is
+unbound, then the <option> for the empty-string choice will get selected="selected".
+>>> class FrameworkForm(Form):
+... name = CharField()
+... language = ChoiceField(choices=[('', '------'), ('P', 'Python'), ('J', 'Java')])
+>>> f = FrameworkForm(auto_id=False)
+>>> print f['language']
+<select name="language">
+<option value="" selected="selected">------</option>
+<option value="P">Python</option>
+<option value="J">Java</option>
+</select>
+
You can specify widget attributes in the Widget constructor.
>>> class FrameworkForm(Form):
... name = CharField()
Please sign in to comment.
Something went wrong with that request. Please try again.