小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

使用DateValidator判断用户输入的日期格式,并用DateFormatter对输入日期格式化。

示例:

代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" viewSourceURL="srcview/index.html">

    
<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="mois: MM, jour: DD, année: YYYY"/>

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

    
<mx:Panel title="Exemple de DateFormatter " width="95%" height="95%"
            paddingTop
="10" paddingLeft="5" paddingRight="5" paddingBottom="10">

        
<mx:Form width="100%">
            
<mx:FormItem label="Entrer une date (mm/dd/yyyy):" width="100%">
                
<mx:TextInput id="dob" text=""/>
            
</mx:FormItem>

            
<mx:FormItem label="Date Formatée: " width="100%">
                
<mx:TextInput id="formattedDate" text="" editable="false"/>
            
</mx:FormItem>

            
<mx:FormItem>
                
<mx:Button label="Valider et Formater" click="Format();"/>
            
</mx:FormItem>
        
</mx:Form>

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

点击查看源文件

来自:http://www.flex-tutorial.fr/2008/05/18/flex-formatter-exemple-de-dateformatter-en-mxml/

posted on 2008-05-19 16:34  『小小菜鸟』  阅读(2680)  评论(0编辑  收藏  举报