Customizing the Flex DateChooser control

by Peter deHaan on December 21, 2007

in DateBase, DateChooser

The following example shows how you can customize the DateChooser control in Flex by using an embedded font, customizing the header styles, week day names, week day name styles, and colors by setting various styles and properties.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/21/customizing-the-flex-datechooser-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        @font-face {
            src: local("Base 02");
            fontFamily: Base02Embedded;
            unicode-range:
                U+0030-U+0039, /* 0-9 */
                U+0041-U+0051, /* Uppercase A-Z */
                U+0052-U+007A, /* Lowercase a-z */
                U+002F-U+002F; /* slash (/) */
        }

        DateChooser {
            cornerRadius: 0; /* pixels */
            headerColors: black, black;
            borderColor: black;
            themeColor: black;
            fontFamily: Base02Embedded;
            todayColor: red;
            todayStyleName: myTodayStyleName;
            headerStyleName: myHeaderStyleName;
            weekDayStyleName: myWeekDayStyleName;
            dropShadowEnabled: true;
        }

        .myTodayStyleName {
            color: white;
        }

        .myWeekDayStyleName {
            fontWeight: normal;
        }

        .myHeaderStyleName {
            color: red;
            fontSize: 16;
            fontWeight: normal;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.formatters.DateBase;

            private function dateChooser_init():void {
                dateChooser.dayNames = DateBase.dayNamesShort;
            }
        ]]>
    </mx:Script>

    <mx:DateChooser id="dateChooser"
            initialize="dateChooser_init();" />

</mx:Application>

View source is enabled in the following example.

I didn’t include the TrueType font in the source code ZIP. If you want to grab that exact font, head over to the creator’s site @ http://www.stereo-type.net/ and download “Base 02″.

For an example of using embedded fonts with the Flex DateField control, see “Embedding fonts for the Flex DateField control”.

{ 6 comments… read them below or add one }

1 kichuz October 14, 2008 at 12:36 am

Hello!

Can anyone please tell me how can i separately display year and month in a DateChooser…like I want to display year on top of the month …. and which has separate navigator like we have for month..

Thanks…

kichuz

Reply

2 moonw December 4, 2008 at 9:28 am

try this property yearNavigationEnabled=”true”
and go check official documentation

http://livedocs.adobe.com/flex/2/langref/mx/controls/DateChooser.html#includeExamplesSummary

Reply

3 Andrew February 16, 2009 at 3:45 am

Thanks for this – What about applying a background image (behind the days)?

Reply

4 LJ November 19, 2009 at 2:11 pm

When you click a date in the date chooser does anyone know where that information is stored in the code so i can call it later?

Reply

5 Peter deHaan November 19, 2009 at 6:25 pm

@LJ,

You can get the currently selected date by using the selectedDate property:

<mx:DateChooser id="dc" />
<mx:Label text="{dc.selectedDate.toDateString()}" />

Peter

Reply

6 preeti December 10, 2009 at 9:49 pm

can we see datechooser control in grid view in flex…?

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: