Ticket #4622: SelectDateWidget.diff
File SelectDateWidget.diff, 1.6 KB (added by , 17 years ago) |
---|
-
django/newforms/extras/widgets.py
57 57 y, m, d = data.get(self.year_field % name), data.get(self.month_field % name), data.get(self.day_field % name) 58 58 if y and m and d: 59 59 return '%s-%s-%s' % (y, m, d) 60 return None60 return data.get(name, None) -
tests/regressiontests/forms/tests.py
3536 3536 <option value="2016">2016</option> 3537 3537 </select> 3538 3538 3539 Using a SelectDateWidget in a form: 3540 3541 >>> class GetDate(Form): 3542 ... mydate = DateField(widget=SelectDateWidget) 3543 >>> a = GetDate({'mydate_month':'4', 'mydate_day':'1', 'mydate_year':'2008'}) 3544 >>> print a.is_valid() 3545 True 3546 >>> print a.cleaned_data['mydate'] 3547 2008-04-01 3548 3549 As with any widget that implements get_value_from_datadict, 3550 we must be prepared to accept the input from the "as_hidden" 3551 rendering as well. 3552 3553 >>> print a['mydate'].as_hidden() 3554 <input type="hidden" name="mydate" value="2008-4-1" id="id_mydate" /> 3555 >>> b=GetDate({'mydate':'2008-4-1'}) 3556 >>> print b.is_valid() 3557 True 3558 >>> print b.cleaned_data['mydate'] 3559 2008-04-01 3560 3561 3539 3562 # MultiWidget and MultiValueField ############################################# 3540 3563 # MultiWidgets are widgets composed of other widgets. They are usually 3541 3564 # combined with MultiValueFields - a field that is composed of other fields.