Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored February 21, 2007

Showing 1 changed file with 13 additions and 0 deletions. Show diff stats Hide diff stats

  1. 13  tests/regressiontests/forms/tests.py
13  tests/regressiontests/forms/tests.py
@@ -2011,6 +2011,19 @@
2011 2011
 <option value="J">Java</option>
2012 2012
 </select>
2013 2013
 
  2014
+A subtlety: If one of the choices' value is the empty string and the form is
  2015
+unbound, then the <option> for the empty-string choice will get selected="selected".
  2016
+>>> class FrameworkForm(Form):
  2017
+...     name = CharField()
  2018
+...     language = ChoiceField(choices=[('', '------'), ('P', 'Python'), ('J', 'Java')])
  2019
+>>> f = FrameworkForm(auto_id=False)
  2020
+>>> print f['language']
  2021
+<select name="language">
  2022
+<option value="" selected="selected">------</option>
  2023
+<option value="P">Python</option>
  2024
+<option value="J">Java</option>
  2025
+</select>
  2026
+
2014 2027
 You can specify widget attributes in the Widget constructor.
2015 2028
 >>> class FrameworkForm(Form):
2016 2029
 ...     name = CharField()

0 notes on commit 5bec651

Please sign in to comment.
Something went wrong with that request. Please try again.