1 Reply Latest reply on Sep 22, 2010 3:30 AM by Anitha Selvaraj

    how make DateField alway is DD/MM/YYYY ?

    quoc_thai Level 1

      Hi all,

       

           I have used DateField, I want result of date is : DD/MM/YYYY.

       

           Example:

       

                I enter 20/10/2010 ---> show : 20/10/2010  --> ok

                I enter 2/10/2010 ---> show : 2/10/2010  --> I want is 02/10/2010 not 2/10/2010.

                I enter 20/1/2010 ---> show : 20/1/2010  --> I want is 20/01/2010 not 20/1/2010.

       

           I can split this date string to DD/MM/YYYY but DateValidator has support ?

          

          My code is:

          

      private

       

      function formatDate(date:Date):String {

       

      return dfconv.format(date);

      }

       

      private

       

      function show():void{

       

      dateField.formatString = "DD/MM/YYYY";

      Alert.show(dateField.text);                         ----> must is: "DD/MM/YYYY"

      }

       

      ...

      ...

       

      <mx:DateFormatter

      id="dfconv" formatString="DD/MM/YYYY"/>

       

          

       

      <mx:DateValidator

      source="

      {dateField}"

      property="

      text"

      inputFormat="

      DD/MM/YYYY"

      wrongLengthError="

      The date format is not correct"

      allowedFormatChars="

      /"

      trigger="

      {checkDate}"

      triggerEvent="

      click"

      valid="{Alert.show(

      'Date is valid')}"

      invalid="{Alert.show(

      'Date is invalid')}"/>

       

      <mx:DateField

      id="dateField" labelFunction="formatDate"

           width="

      104" parseFunction="null"

           horizontalCenter="

      10" verticalCenter="10" editable="true"/>

       

      <mx:Button

      label="Check Date" id="checkDate" click="show()"/>

       

      Thanks