hey there is a very good example for date formatter as well as date validator

just try out,, mght be its a thing which u want

<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the Formatter. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">

<mx:Script>
<![CDATA[

import mx.events.ValidationResultEvent;
private var vResult:ValidationResultEvent;

// Event handler to validate and format input.
private function Format():void
{
vResult = dateVal.validate();
if (vResult.type==ValidationResultEvent.VALID) {
formattedDate.text=dateFormatter.format(dob.text);
}

else {
formattedDate.text= "";
}
}
]]>
</mx:Script>

<mx:DateFormatter id="dateFormatter" formatString="month: MM, day: DD, year: YYYY"/>

<mx:DateValidator id="dateVal" source="{dob}" property="text" inputFormat="mm/dd/yyyy"/>

<mx:Panel title="Formatter Example using the DateFormatter class" width="75%" height="75%"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

<mx:Label text="Enter date (mm/dd/yyyy):"/>
<mx:TextInput id="dob" text="" width="50%"/>

<mx:Button label="Validate and Format" click="Format();"/>
<mx:TextInput id="formattedDate" editable="false" width="50%"/>

</mx:Panel>
</mx:Application>

tyombria <[EMAIL PROTECTED]> wrote:
Hi, Misael.
When you define a labelFunction for the DateField component to
format date for output you must also define parseFunction. Inverse
function to labelFunction.
For example:
private var dateField : DateField = new DateField();
dateField.labelFunction = myLabelFunction;
dateField.parseFunction = myParseFunction;

private function myLabelFunction( date : Date ) : String {
  var df : DateFormatter = new DateFormatter();
  df.formatString = "DD/MM/YYYY";
  return df.format( date );
}

public function myParseFunction( inputString : String,
formatString : String = "DD/MM/YYYY") : Date {
  if (inputString == "") {
    return null;
  }                       
                       
var year : Number = Number(inputString.substr(6,4));
var month : Number = Number(inputString.substr(3,2)) - 1;
var day : Number = Number(inputString.substr(0,2));
var date : Date = new Date(year,month,day);
return date;
}

--- In [email protected], poonam vora <[EMAIL PROTECTED]> wrote:
>
> hie misael
> u can try this way.
> i think its a return function mistake
> it has to be String not void.
>
> example
>
> <mx:DateFormatter id="dfconv" formatString="YYYY/MM/DD"/>
> <mx:Script>
>     <![CDATA[
>         private function formatDate(date:Date):String
>         {
>             return dfconv.format(date);
>         }       
>     ]]>
> </mx:Script>
>
> instruction:
> You can choose a different name for the function,
> but it must take a single argument of type Date and
> return the date as a String for display in the text field.
>
> bye,,
>
> Misael <[EMAIL PROTECTED]> wrote:    Hi,
> I have a dateField on which i want to format the displayed date. I
want to show it like "DD/MM/YYYY". I´m trying to use this function
with a call in the  change="formatNasc(DateField
(event.target).selectedDate)" event, but it still displays
in "MM/DD/YYYY" format.
>
>  private function formatNasc(date:Date):void{
>     var formatter:DateFormatter = new DateFormatter();
>     formatter.formatString = "DD/MM/YYYY";   
>      xClienteDataNasc.text = formatter.format(date);
> }
>
> What´s the point here?
> Regards.
>     
>
>   --
>  Flexcoders Mailing List
>  FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>  Search Archives: http://www.mail-archive.com/flexcoders%
40yahoogroups.com
>
>              
>
>         SPONSORED LINKS  
>                                                     Web site
design development                                       Computer
software development                                       Software
design and
development                                                         
           Macromedia flex                                      
Software development best
practice                                                 
>      
> ---------------------------------
>    YAHOO! GROUPS LINKS

>    
>     Visit your group "flexcoders" on the web.
>    
>     To unsubscribe from this group, send an email to:
>  [EMAIL PROTECTED]
>    
>     Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.

>    
> ---------------------------------


>     
>
>                        
> ---------------------------------
>   Yahoo! India Answers Share what your know-how and wisdom
>  Send free SMS to your Friends on Mobile from your Yahoo!
Messenger Download now
>







	
		
Yahoo! India Answers Share what your know-how and wisdom
Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download now

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to