| | 3638 | Using 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() |
|---|
| | 3644 | True |
|---|
| | 3645 | >>> print a.cleaned_data['mydate'] |
|---|
| | 3646 | 2008-04-01 |
|---|
| | 3647 | |
|---|
| | 3648 | As with any widget that implements get_value_from_datadict, |
|---|
| | 3649 | we must be prepared to accept the input from the "as_hidden" |
|---|
| | 3650 | rendering 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() |
|---|
| | 3656 | True |
|---|
| | 3657 | >>> print b.cleaned_data['mydate'] |
|---|
| | 3658 | 2008-04-01 |
|---|
| | 3659 | |
|---|
| | 3660 | |
|---|