#5145: MultiWidget / MultiValueField does not interpret initial data
-----------------------------+----------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Status: new | Component: django.newforms
Version: SVN | Keywords: newforms, MultiWidget,
MultiValueField, initial
Stage: Unreviewed | Has_patch: 0
-----------------------------+----------------------------------------------
Below I've used SplitDateTime as an example, but it applies to other
MultiWidget / MultiValueField as well, as I came across the issue using a
custom MultiWidget / MultiValueField. I'm not sure in which the problem
lies. Generally, the MultiValueField accepts values from the "data="
argument to the form constructor, and these appear when the MultiWidget is
rendered just fine. However, when a dictionary is passed through the
"initial=" argument, it does not appear. An example follows:
{{{
>>> from django.newforms import *
>>> class TestForm(Form):
... the_datetime_field =
SplitDateTimeField(widget=SplitDateTimeWidget)
...
>>> test_data = {'the_datetime_field_0':'12/24/07',
'the_datetime_field_1':'15:00'}
>>> unbound_form_no_initial = TestForm()
>>> unbound_form_no_initial.as_p()
u'<p><label for="id_the_datetime_field_0">The datetime field:</label>
<input type="text" name="the_datetime_field_0"
id="id_the_datetime_field_0" /><input type="text"
name="the_datetime_field_1" id="id_the_datetime_field_1" /></p>'
>>> bound_form = TestForm(data=test_data)
>>> bound_form.as_p()
u'<p><label for="id_the_datetime_field_0">The datetime field:</label>
<input type="text" name="the_datetime_field_0" value="12/24/07"
id="id_the_datetime_field_0" /><input type="text"
name="the_datetime_field_1" value="15:00" id="id_the_datetime_field_1"
/></p>'
>>> unbound_form_with_initial = TestForm(initial=test_data)
>>> unbound_form_with_initial.as_p()
u'<p><label for="id_the_datetime_field_0">The datetime field:</label>
<input type="text" name="the_datetime_field_0"
id="id_the_datetime_field_0" /><input type="text"
name="the_datetime_field_1" id="id_the_datetime_field_1" /></p>'
}}}
As you can see, only the bound form shows the values. The first unbound
form is of course not supposed to show any initial values. However, the
second unbound form is passed initial values that it is supposed to show,
but it does not.
--
Ticket URL: <http://code.djangoproject.com/ticket/5145>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---