2 Replies Latest reply on Dec 17, 2010 5:47 AM by JoshBeall

    Fire all validators on a component

    JoshBeall Level 1

      Hi All,


      I've got a custom component I've written that has three validators.  If all the validators pass their validation tests, then I know that the user input entered into that component is valid.


      I am putting an "isValid()" method on my component that the hosting application can call to see if the user input in the component is valid.  My thinking is that I can check the results of the validate method on my three validators, and use that to determine whether the user input is valid or not.  I'm wondering if I need to manually specify each validator to check, or is there a way I can say "run all the validators in this component?"


      Or, is there a collection somewhere that will have all the validators in my component?  I could then iterate over the validators and call .validate() on all those objects.



        • 1. Re: Fire all validators on a component
          saisri2k2 Level 4

          validatorArr=new Array();
                              var errors:Array=Validator.validateAll(validatorArr);




          <mx:StringValidator id="txtfname_stringvalidator"
                                             requiredFieldError="First Name"/>
                    <mx:StringValidator id="txtlname_stringvalidator"
                                             requiredFieldError="Last Name"/>
                    <mx:StringValidator id="txtloginname_stringvalidator"
                                             requiredFieldError="User Name"/>



          is this what you are talking about?

          • 2. Re: Fire all validators on a component
            JoshBeall Level 1

            No.  You manually pushed some validators into an array in your example.  I am wondering if there is a way to retrieve all the validators in a component and iterate over them, without having to manually create the list (as you did, manually creating an array of validators).


            That way, I can add/remove validators to my component, and then the code that iterates over all validators will work without being altered.