3 Replies Latest reply on Sep 3, 2008 8:15 PM by Newsgroup_User

    Multiple Source Validators

    BrandG
      I have two edit boxes, "Password" and "Password Confirm". I want to use Flex's validators correctly wherever possible, and this looks like an obvious choice. However, if I make a custom validator, it has only one source passed to it. Is there any way to read from both sources in a validator? Or should I just punt and fake a validation errortip when the user submits invalid data?
        • 1. Re: Multiple Source Validators
          Level 7

          "BrandG" <webforumsuser@macromedia.com> wrote in message
          news:g9mu7u$5cl$1@forums.macromedia.com...
          >I have two edit boxes, "Password" and "Password Confirm". I want to use
          >Flex's
          > validators correctly wherever possible, and this looks like an obvious
          > choice.
          > However, if I make a custom validator, it has only one source passed to
          > it. Is
          > there any way to read from both sources in a validator? Or should I just
          > punt
          > and fake a validation errortip when the user submits invalid data?

          I just define the validator and don't use the source. Instead, I use
          something like this:

          //when the focus leaves a control connected to a DataItem

          private function dataItemFocusOut(di:DataItem, e:Event):void{

          var result:ValidationResultEvent;

          if (di.validatorType=='StringValidator'){

          var sV:StringValidator=sValidator;

          sV.minLength=di.minLength;

          sV.maxLength=di.maxLength;

          sV.listener=e.currentTarget;

          sV.required=di.isRequired;

          result = sV.validate(e.currentTarget.text);

          } else if (di.validatorType=='EMailValidator'){

          var eV:EmailValidator=eValidator;

          eV.listener = e.currentTarget;

          eV.required = di.isRequired;

          result = eV.validate(e.currentTarget.text);

          } else {

          trace('this code doesn\'t provide a validator of type
          "'+di.validatorType+'".');

          var dontValidate:Boolean=true;

          }

          if (result.type==ValidationResultEvent.VALID){

          di.isValid=true;

          di.value=e.currentTarget.text;

          } else if (!dontValidate) {

          di.isValid=false;

          }

          }



          The mxml that makes it work looks like this:

          <mx:FormItem label="First Name *">

          <mx:TextInput id="firstName" width="250" text="{contactDetails.firstName}"

          focusOut="dataItemFocusOut(contactDetails.firstName, event)"/>

          </mx:FormItem>

          HTH;



          Amy


          • 2. Re: Multiple Source Validators
            BrandG Level 1
            Amy, you are a focused ray of helpful win.

            So thorough, specific, and quick, it's almost like you had the code on hand already.

            Seriously, thanks. I probably would have spent a week digging into the Flex source to build my own validator descendant. :)
            • 3. Re: Multiple Source Validators
              Level 7

              "BrandG" <webforumsuser@macromedia.com> wrote in message
              news:g9n007$76b$1@forums.macromedia.com...
              > Amy, you are a focused ray of helpful win.
              >
              > So thorough, specific, and quick, it's almost like you had the code on
              > hand
              > already.
              >
              > Seriously, thanks. I probably would have spent a week digging into the
              > Flex
              > source to build my own validator descendant. :)

              You're welcome :-)