Author: mtredinnick
Date: 2007-08-11 21:15:35 -0500 (Sat, 11 Aug 2007)
New Revision: 5859
Modified:
django/trunk/django/newforms/extras/widgets.py
django/trunk/tests/regressiontests/forms/tests.py
Log:
Fixed #4622 -- Fixed SelectDateWidget to work correctly when used as a hidden
input field. Thanks, Bill Fenner.
Modified: django/trunk/django/newforms/extras/widgets.py
===================================================================
--- django/trunk/django/newforms/extras/widgets.py 2007-08-12 02:14:52 UTC
(rev 5858)
+++ django/trunk/django/newforms/extras/widgets.py 2007-08-12 02:15:35 UTC
(rev 5859)
@@ -57,4 +57,4 @@
y, m, d = data.get(self.year_field % name), data.get(self.month_field
% name), data.get(self.day_field % name)
if y and m and d:
return '%s-%s-%s' % (y, m, d)
- return None
+ return data.get(name, None)
Modified: django/trunk/tests/regressiontests/forms/tests.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests.py 2007-08-12 02:14:52 UTC
(rev 5858)
+++ django/trunk/tests/regressiontests/forms/tests.py 2007-08-12 02:15:35 UTC
(rev 5859)
@@ -3635,6 +3635,29 @@
<option value="2016">2016</option>
</select>
+Using a SelectDateWidget in a form:
+
+>>> class GetDate(Form):
+... mydate = DateField(widget=SelectDateWidget)
+>>> a = GetDate({'mydate_month':'4', 'mydate_day':'1', 'mydate_year':'2008'})
+>>> print a.is_valid()
+True
+>>> print a.cleaned_data['mydate']
+2008-04-01
+
+As with any widget that implements get_value_from_datadict,
+we must be prepared to accept the input from the "as_hidden"
+rendering as well.
+
+>>> print a['mydate'].as_hidden()
+<input type="hidden" name="mydate" value="2008-4-1" id="id_mydate" />
+>>> b=GetDate({'mydate':'2008-4-1'})
+>>> print b.is_valid()
+True
+>>> print b.cleaned_data['mydate']
+2008-04-01
+
+
# MultiWidget and MultiValueField #############################################
# MultiWidgets are widgets composed of other widgets. They are usually
# combined with MultiValueFields - a field that is composed of other fields.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---