Django

Code

Changeset 5859

Show
Ignore:
Timestamp:
08/11/07 21:15:35 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4622 -- Fixed SelectDateWidget? to work correctly when used as a hidden input field. Thanks, Bill Fenner.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/extras/widgets.py

    r5819 r5859  
    5858        if y and m and d: 
    5959            return '%s-%s-%s' % (y, m, d) 
    60         return None 
     60        return data.get(name, None) 
  • django/trunk/tests/regressiontests/forms/tests.py

    r5819 r5859  
    36363636</select> 
    36373637 
     3638Using a SelectDateWidget in a form: 
     3639 
     3640>>> class GetDate(Form): 
     3641...     mydate = DateField(widget=SelectDateWidget) 
     3642>>> a = GetDate({'mydate_month':'4', 'mydate_day':'1', 'mydate_year':'2008'}) 
     3643>>> print a.is_valid() 
     3644True 
     3645>>> print a.cleaned_data['mydate'] 
     36462008-04-01 
     3647 
     3648As with any widget that implements get_value_from_datadict, 
     3649we must be prepared to accept the input from the "as_hidden" 
     3650rendering as well. 
     3651 
     3652>>> print a['mydate'].as_hidden() 
     3653<input type="hidden" name="mydate" value="2008-4-1" id="id_mydate" /> 
     3654>>> b=GetDate({'mydate':'2008-4-1'}) 
     3655>>> print b.is_valid() 
     3656True 
     3657>>> print b.cleaned_data['mydate'] 
     36582008-04-01 
     3659 
     3660 
    36383661# MultiWidget and MultiValueField ############################################# 
    36393662# MultiWidgets are widgets composed of other widgets. They are usually