3 Replies Latest reply on Oct 9, 2009 5:55 AM by ShardulSingh

    Showing error message in Datevalidator

    gandhi.tush Level 1

      Hi,

      I am using datefield component for date of birth.

      I am using date validator for this.

      My code is like this:-

       

       

       

       

       

       

       

       

       

       

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

      >

       

       

      <!--<mx:DateChooser width="300" height="300"/>-->

       

       

      <mx:DateValidator source="{date}" property="text" allowedFormatChars="/" trigger="{mybutton}" triggerEvent="click"

      valid="Alert.show('Validation Succeeded!');" wrongDayError="Enter corect day"

      />

       

       

      <mx:VBox>

       

       

       

      <mx:DateField id="date" width="300" height="20" editable="true"

      />

       

       

       

       

      <mx:Button id="mybutton" click="getDate()" label="validate"/>

       

       

      </mx:VBox>

      </mx:Application>

       

      My problem whenever I am adding incorrect day, I am getting an error "Enter correct day". But that appears only when I am mouse over on datefield.

      I want to show that continuously on browser.

      Is there any way to do that?

      Any help appreciated.

      Thanks,

      Tushar Gandhi

        • 1. Re: Showing error message in Datevalidator
          ShardulSingh Level 3

          Hi,

          you are saying that, " I want to show that continuously on browser.".

          Did you mean the classic validation like the message in the Alert window,or you want like the validation summary,which in

          normal html pages we gets when we press the submit button.Pls give the detail about this.

          and also put your 'getDate()' method here.

           

           

           

           

          with Regards,

          Shardul Singh Bartwal

          • 2. Re: Showing error message in Datevalidator
            gandhi.tush Level 1

            Hi,

            Yes Iwant to show the error continuously on browser.

            Also I am having one more trouble. Whenever I am trying to get current date by **** like this

             

             

             

            var

             

             

            "Date is "+da.getDate());

             

            I am getting only the day. I want whole date.

            How should I do that?

            Any help appreciated,

            Thanks,

            Tushar Gandhi.

             

            da:Date=new Date();

            Alert.show(

            • 3. Re: Showing error message in Datevalidator
              ShardulSingh Level 3

              Hi, pls find the solution for your problem.I have created the demo application for this.

              Pls check it.And still you have not given the method getDate().So pls specify that method for more accurate solution.

              Let me know if you have any issue with this.

               

               

               

               

              <?xml version="1.0" encoding="utf-8"?>

              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()">

              <mx:Script>

                <![CDATA[

                 import mx.controls.Alert;

                 import mx.collections.ArrayCollection;

                 import mx.managers.CursorManager;

                 import mx.validators.*;

                 import mx.rpc.events.ResultEvent;

                 import mx.events.ValidationResultEvent;

                 

                      [Bindable]

                      private var validatorArr:Array;

                    

                      private var shipping:Boolean=false;

                     

                    private function init():void

                      {

                       validatorArr = new Array;

                       validatorArr.push(dateVld);

                      }

                    

                    private function funValidateForm(event:MouseEvent):void

                    {

                        var validatorErrorArr:Array = Validator.validateAll(validatorArr);

                        var isValidForm:Boolean = Boolean(validatorErrorArr.length == 0);

                        if(isValidForm)

                        {

                            Alert.show("Validation Successful","Validation Summary !");

                          }

                      else

                      {

                             var err:ValidationResultEvent;

                             var errorMessageArray:Array=[];

                             for each (err in validatorErrorArr)

                             {

                               var errField:String = FormItem

                               (err.currentTarget.source.parent.parent).label

                               errorMessageArray.push(err.message);

                             }

                                Alert.show(errorMessageArray.join("\n"),"Validation Summary !");

                       }

                    } 

                 ]]>

              </mx:Script>

               

              <mx:DateValidator id="dateVld" source="{date}"  property="text" required="true" requiredFieldError="Please Enter Date."/>

               

                 <mx:VBox id="mainVBox"  width="500" height="180" verticalGap="10" backgroundColor="0xCCCCCC" cornerRadius="5" borderStyle="solid">

                        <mx:Form width="100%" height="100%" cornerRadius="5" defaultButton="{mybutton}">

                           <mx:FormItem label="Date:">

                                <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle" horizontalGap="1">

                                      <mx:DateField id="date" width="150" yearNavigationEnabled="true" editable="true"/>

                                       <mx:Label text="*" color="red"/>

                                    </mx:HBox>

                               </mx:FormItem>

                            <mx:Button id="mybutton" label="Submit" click="funValidateForm(event)"/>

                    </mx:Form>

                

                       </mx:VBox>  

              </mx:Application>

               

               

               

               

              with Regards,

              Shardul Singh Bartwal