mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #4412 -- Added support for optgroups, both in the model when defining choices, and in the form field and widgets when the optgroups are displayed. Thanks to Matt McClanahan <cardinal@dodds.net>, Tai Lee <real.human@mrmachine.net> and SmileyChris for their contributions at various stages in the life of this ticket.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7977 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -458,6 +458,35 @@ over multiple times without getting consumed:
|
||||
<option value="4">4</option>
|
||||
</select>
|
||||
|
||||
Choices can be nested one level in order to create HTML optgroups:
|
||||
>>> w.choices=(('outer1', 'Outer 1'), ('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))))
|
||||
>>> print w.render('nestchoice', None)
|
||||
<select name="nestchoice">
|
||||
<option value="outer1">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1">Inner 1</option>
|
||||
<option value="inner2">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
>>> print w.render('nestchoice', 'outer1')
|
||||
<select name="nestchoice">
|
||||
<option value="outer1" selected="selected">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1">Inner 1</option>
|
||||
<option value="inner2">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
>>> print w.render('nestchoice', 'inner1')
|
||||
<select name="nestchoice">
|
||||
<option value="outer1">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1" selected="selected">Inner 1</option>
|
||||
<option value="inner2">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
# NullBooleanSelect Widget ####################################################
|
||||
|
||||
>>> w = NullBooleanSelect()
|
||||
@@ -626,6 +655,44 @@ True
|
||||
>>> w._has_changed([1, 2], [u'1', u'3'])
|
||||
True
|
||||
|
||||
# Choices can be nested one level in order to create HTML optgroups:
|
||||
>>> w.choices = (('outer1', 'Outer 1'), ('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))))
|
||||
>>> print w.render('nestchoice', None)
|
||||
<select multiple="multiple" name="nestchoice">
|
||||
<option value="outer1">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1">Inner 1</option>
|
||||
<option value="inner2">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
>>> print w.render('nestchoice', ['outer1'])
|
||||
<select multiple="multiple" name="nestchoice">
|
||||
<option value="outer1" selected="selected">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1">Inner 1</option>
|
||||
<option value="inner2">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
>>> print w.render('nestchoice', ['inner1'])
|
||||
<select multiple="multiple" name="nestchoice">
|
||||
<option value="outer1">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1" selected="selected">Inner 1</option>
|
||||
<option value="inner2">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
>>> print w.render('nestchoice', ['outer1', 'inner2'])
|
||||
<select multiple="multiple" name="nestchoice">
|
||||
<option value="outer1" selected="selected">Outer 1</option>
|
||||
<optgroup label="Group "1"">
|
||||
<option value="inner1">Inner 1</option>
|
||||
<option value="inner2" selected="selected">Inner 2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
# RadioSelect Widget ##########################################################
|
||||
|
||||
>>> w = RadioSelect()
|
||||
|
||||
Reference in New Issue
Block a user