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"/>


5 Responses to “Flex DateField and formats”

  1. February 12th, 2008 | 5:14 pm

    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.

  2. abu
    February 28th, 2008 | 3:28 am

    It’s cool

  3. Pramod Rao
    June 2nd, 2008 | 10:30 pm

    Hey thanks dude…. I literally banged my head yesterday for this and it all boiled down to this one single line…

  4. flexo
    October 17th, 2008 | 2:04 pm

    Thanks for such a nice example. God bless you

  5. November 10th, 2008 | 7:41 pm

    plsy blak jak free…

    Hancock.collapsed Okinawa …

Leave a reply