An error handler function for DateFormatter : DateFormatter « Data Model « Flex






An error handler function for DateFormatter

An error handler function for DateFormatter
    

<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".

This user guide is licensed for use under the terms of the Creative Commons Attribution 
Non-Commercial 3.0 License. 

This License allows users to copy, distribute, and transmit the user guide for noncommercial 
purposes only so long as 
  (1) proper attribution to Adobe is given as the owner of the user guide; and 
  (2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms. 
The best way to provide notice is to include the following link. 
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

-->


    <!-- formatters\FormatterSimpleErrorForDevApps.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <fx:Script> 
         
        private function formatWithError(value:Object):String { 
            var formatted:String = myFormatter.format(value); 
            if (formatted == "") { 
                if (myFormatter.error != null ) { 
                    if (myFormatter.error == "Invalid value") { 
                        formatted = ": The value is not valid."; 
                    } 
                    else { 
                        formatted = ": The formatString is not valid."; 
                    } 
                } 
            } 
            return formatted; 
        } 
      
    </fx:Script>
    <fx:Declarations>
        <!-- Declare a formatter and specify formatting properties.-->
        <mx:DateFormatter id="myFormatter" formatString="MXXXMXMXMXMXM" />
    </fx:Declarations>
    <!-- Trigger the formatter while populating a string with data.-->
    <s:TextInput id="myTI" width="75%"
        text="Your order shipped on {formatWithError('May 23, 2005')}" />
</s:Application>

   
    
    
    
  








Related examples in the same category

1.Formatting the Date as a Date objectFormatting the Date as a Date object
2.Formatting the Date as a StringFormatting the Date as a String
3.DateFormatter format string MM/DD/YYDateFormatter format string MM/DD/YY
4.DateFormatter format string "MMM DD, YYDateFormatter format string
5.DateFormatter format string MMMM DD, YYYYDateFormatter format string MMMM DD, YYYY
6.Set format string for DateFormatterSet format string for DateFormatter
7.Data Formatting with DateFormatterData Formatting with DateFormatter
8.Declare a DateFormatter component with an MM/DD/YYYY date format, and binds the formatted version of a Date object
9.Declare a DateFormatter with an MM/DD/YYYY date formatDeclare a DateFormatter with an MM/DD/YYYY date format
10.Using the DateFormatter classUsing the DateFormatter class
11.Use DateFormatter to format Date valueUse DateFormatter to format Date value
12.Formatting dates using the DateFormatter
13.Use a DateFormatter object to do the formattingUse a DateFormatter object to do the formatting
14.declares a DateFormatter component with an MM/DD/YYYY date formatdeclares a DateFormatter component with an MM/DD/YYYY date format
15.DateFormatter and parametersDateFormatter and parameters
16.Example Date FormatterExample Date Formatter
17.DateField FormatterDateField Formatter