views:

55

answers:

1

How does one set the date on the CalendarDatePicker. i.e. it defaults to current date and I want to display it with another date which I will set from my controller.

I am displaying the CalendarDatePicker widget in a TableForm from tw.form. I have looked at this for a few hours and can't work out how to do this so any pointers greatly appreciated.

import tw.forms as twf

form = twf.TableForm('dateSel', action='changeDate', children=[ twf.CalendarDatePicker('StartDate', date_format = "%d/%m/%Y"), twf.CalendarDatePicker('EndDate', date_format = "%d/%m/%Y" ) ])

A: 

I don't have a copy of twforms laying around, but based on their sample code, it looks like you might want to do something like:

from datetime import datetime

start = twf.CalendarDatePicker('StartDate', date_format = "%d/%m/%Y")
start.default = datetime.now() # or any valid datetime object

end = twf.CalendarDatePicker('EndDate', date_format = "%d/%m/%Y" )
start.default = datetime.now() # or any valid datetime object

form = twf.TableForm('dateSel', action='changeDate', children=[start, end])
John Paulett
Thanks was missing the .default=
Daniel