2 Replies Latest reply on Jul 12, 2006 9:07 AM by dzlmbq

    Catching DateValidator errors

    dzlmbq
      I am trhying to use a DateValidator in ActionScript to validate fields before going to a new screen. I need to catch any errors from the validator and not display them. Has anyone came across a way to catch errors from validators? Here is the code I am working with:

        • 1. Re: Catching DateValidator errors
          Level 7
          Hi,

          There is a section in the doc on handling validator errors here:

          http://livedocs.macromedia.com/flex/2/docs/00001068.html

          You can see the entire chapter on validators here:

          http://livedocs.macromedia.com/flex/2/docs/00001054.html

          Stephen



          "dzlmbq" <webforumsuser@macromedia.com> wrote in message
          news:e90b31$k5l$1@forums.macromedia.com...
          >I am trhying to use a DateValidator in ActionScript to validate fields
          >before
          > going to a new screen. I need to catch any errors from the validator and
          > not
          > display them. Has anyone came across a way to catch errors from
          > validators?
          > Here is the code I am working with:
          >
          >
          >
          > <?xml version="1.0" encoding="utf-8"?>
          > <mx:Application xmlns:mx=" http://www.macromedia.com/2003/mxml"
          > xmlns:local="*"
          > backgroundColor="#FFFFFF">
          >
          > <mx:Script>
          > <![CDATA[
          > import mx.controls.Alert;
          >
          > var localDateField:String = "";
          >
          > private function validateDate():Void {
          > try {
          > localDateField = taMain.text;
          >
          > mx.validators.DateValidator.isValid(this, 'localDateField');
          > } catch (e) {
          > Alert.show(e);
          > }
          > }
          > ]]>
          > </mx:Script>
          >
          > <mx:DateValidator field="localDateField" allowedFormatChars="/" />
          >
          > <mx:VBox id="main" >
          > <mx:TextArea id="taMain" height="20" />
          > <mx:Button label="Validate Date" click="validateDate()" />
          > </mx:VBox>
          > </mx:Application>
          >


          • 2. Catching DateValidator errors
            dzlmbq Level 1
            Those are the docs for Flex 2 and the validator syntax is a bit different. I did find a solution by looking at the 1.5 documents. You can interrogate the components errorString to determine if a Validator set an error for it.