Default Flex DateChooser to tomorrow
I have a DateChooser control and I was trying to default it to have tomorrow's date selected. This is actually really easy to do, but it took me a fair amount of time to figure it out, so I thought I'd post this just in case anyone else has some trouble.
Create a variable for today's date:
[Bindable] private var today:Date = new Date();
Then set the selected date of the DateChooser. You may also want to set showToday to false so that today's date isn't highlighted.
<mx:DateChooser selectedDate="{new Date(today.fullYear,today.month,today.date+1)}" showToday="false"/>
The selectedDate property only understands straight dates with no time, which is why I had to assign it this way. If you're at the end of the month/year Flex is smart enough to know that date + 1 should take you to the next month/year.
Here is a sample with view source enabled.
Create a variable for today's date:
[Bindable] private var today:Date = new Date();
Then set the selected date of the DateChooser. You may also want to set showToday to false so that today's date isn't highlighted.
<mx:DateChooser selectedDate="{new Date(today.fullYear,today.month,today.date+1)}" showToday="false"/>
The selectedDate property only understands straight dates with no time, which is why I had to assign it this way. If you're at the end of the month/year Flex is smart enough to know that date + 1 should take you to the next month/year.
Here is a sample with view source enabled.
Comments