Avg. Rating 4.5

Problem

You want to enable year navigation to a DateChooser control in Flex.

Solution

The following example shows how you can toggle year-based navigation on a Flex DateChooser control by setting the yearNavigationEnabled property in MXML and ActionScript.

Detailed explanation

 <?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/07/24/toggling-year-navigation-on-a-datechooser-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">
 
    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="yearNavigationEnabled:">
                <mx:CheckBox id="checkBox" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>
 
    <mx:DateChooser id="dateChooser"
            yearNavigationEnabled="{checkBox.selected}" />
 
</mx:Application>

 You can also set the yearNavigationEnabled property using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/07/24/toggling-year-navigation-on-a-datechooser-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"> <mx:Script> <![CDATA[ private function checkBox_change(evt:Event):void { dateChooser.yearNavigationEnabled = checkBox.selected; } ]]> </mx:Script> <mx:ApplicationControlBar dock="true"> <mx:Form styleName="plain"> <mx:FormItem label="yearNavigationEnabled:"> <mx:CheckBox id="checkBox" change="checkBox_change(event);" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:DateChooser id="dateChooser" /> </mx:Application>

For more information, see "Toggling year navigation on a DateChooser control in Flex" on FlexExamples.com.

Report abuse

Related recipes