Flex DateField and formats
ugh, what a waste of time on this today. SO, you have a DateField control in your fancy uber high UX’d out BRIA form when the business comes to you and says hey, we want the date formated as: DD/MM/YYYY. Sure says you , cake right? So, you precede to the docs on DateField and see a formatString property that accepts a string the same as DateFormatter.formatString. Yippee! NOT! Using the formatString of DD/MMM/YYYY actually formats to ‘12/02022008′, oops. Ok, so you bust out the labelFunction and bamm! Works a treat. Until you programmatically try setting selectedDate on this DateField that is. You have to set the parseFuntion to null to keep Flex from messing with it and your head. Example code below.
Peas
DK
<mx:Script>
<![CDATA[
private function doDateLabel(item:Date):String {
return dateFormatter.format(item);
}
]]>
</mx:Script>
<mx:DateFormatter id="dateFormatter" formatString="DD/MMM/YYYY" />
<mx:DateField id="begin"
showToday="true"
labelFunction="doDateLabel"
parseFunction="null"/>





Thanks, I hit this problem last week, and couldn’t believe it (and yes, it did mess with my head too!). I got as far as working out I needed to do something with the parseFunction, then I ended up leaving it for another day.
If I can just set that to null, then you’ve saved me a lot of time.
Thanks again.
It’s cool
Hey thanks dude…. I literally banged my head yesterday for this and it all boiled down to this one single line…
Thanks for such a nice example. God bless you
Absolutely brilliant. I’d given up on this a year ago….
I was looking for this info, brain freeze, thank you.
Any difference in just doing the following:
I am getting the same results but I didn’t know if there might be another advantage to going through the process you showed.
I meant to show this string, sorry
mx:DateField id=”issDateField” showToday=”true” formatString=”MM-DD-YYYY”
I share your disgust that this little trick is even necessary. Thanks for saving me and my team a lot of pain.
Thanks dude!!
Any follow-up to tim’s message above? I get the same thing. Thanks.
Finally, there is a bug in JIRA for this issue and it waits for your votes!
https://bugs.adobe.com/jira/browse/SDK-25343
Beware, resetting “parseFunction” to null works only for non-editable DateFields.
Better workaround for the time being would be to set “formatString” on DateField to the same value as “formatString” is set for DateFormatter.
e.g.
sample code was eaten by html worm, resubmitting
<mx:DateField id=”begin”
showToday=”true”
labelFunction=”doDateLabel”
parseFunction=”null”/>
and one more time, this time correct sample code:
<mx:DateField id=”begin”
showToday=”true”
labelFunction=”doDateLabel”
formatString=”DD/MMM/YYYY”/>