The following example shows how you can set a minimum and maximum allowable year in the Flex DateField control by setting the minYear and maxYear properties.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/17/setting-a-minimum-and-maximum-allowable-year-in-the-flex-datefield-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:DateField id="dateField"
            yearNavigationEnabled="true"
            minYear="2000"
            maxYear="2010" />

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

3 Responses to Setting a minimum and maximum allowable year in the Flex DateField control

  1. Brett Walker says:

    Yes, although the DateField component is terribly time-consuming/annoying when trying to choose a year that is more than 100 years back. I think the UI for this component needs to be revisited: holding down the arrow button is not really the optimal interface mechanism for this purpose. Another problem with way-back years and DateField is that DateField completely breaks on any years in the BC era (anything before 0, e.g. negative numbers).

  2. Raul Riera says:

    Wow, I want to know why would you need a date that old

  3. John says:

    I wish the time component is more user friendly as has been done on Flex AIR.

Leave a Reply

Your email address will not be published.

You may 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