6 Replies Latest reply on Mar 13, 2009 10:16 PM by Kurrykid

    Qs. about ValidationResult


      I want to validate the form in my accordian. I have created a custom validator for all the required fields and if they are not filled i get the message and all. My only problem is that how do i pass back the subfield within the validation result e.g:

      if(value.Phone == "")
      results.push(new ValidationResult(true, null, "0",
      "Please enter Phone"));
      return results;

      In here I am using null but instead of this I want to use something like personInfo.phone so that the phone gets a red box around it because it is required as in my accordain I have
      the following and phone is a field within personInfo component.

      <view:PersonInfo id="personInfo" />
      <view:Instructions id="instructions" />

      How do I refer it thru the parent

        • 1. Re: Qs. about ValidationResult
          Gregory Lafrance Level 6
          Can't you refer to it as personInfo.phone ?

          Maybe share simplified yet complete code and be more specific as to exactly what you tried and why it does not work (what happened that was wrong, error?).
          • 2. Re: Qs. about ValidationResult
            trycold Level 1

            If I try something like this
            if(value.Phone == "")
            results.push(new ValidationResult(true, personInfo.phone , "0",
            "Please enter Phone"));
            return results;

            then I get an error stating:

            1120: Access of undefined property personInfo

            • 3. Re: Qs. about ValidationResult
              Gregory Lafrance Level 6
              Now we need to know a little more about the structure of your app. Where is personInfo and what is it. Simplified yet complete sample code is best.
              • 4. Re: Qs. about ValidationResult
                trycold Level 1
                In my main app where the aacordian is I have

                id="ItemVal" source="{ItemValidateModel}" property="custName" listener="{addSForm}" />

                where the model is like this:
                <mx:Model id="ItemValidateModel">

                and the listener is <mx:Button id="addSForm" click="addForm()" />

                where the addForm check for the validation like
                private function addForm():void{
                ItemVal.enabled = true;
                vResult = ItemVal.validate(ItemValidateModel.custName);

                if (vResult.type == ValidationResultEvent.INVALID) {
                var t:Array = vResult.results;

                for (var v:int=0; v < t.length; v++) {
                var ec:Number = Number(t[v].errorCode);
                var sf:String = t[v].subField;


                and the phoneInfo is a canvas which have some fields e.g:

                <mx:Label text="Phone #:*" left="leftCol:350" top="topRow:30" />
                <mx:TextInput id="Phone" left="leftCol:450" top="topRow:30" width="40" />

                Basically what I want is the phone should be highlighted when there is no value in there so in here
                var sf:String = t[v].subField; I need the subfiled to refer to phoneinfo.phone which is not working


                • 5. Re: Qs. about ValidationResult
                  Gregory Lafrance Level 6
                  Your error refers to personInfo.

                  1120: Access of undefined property personInfo

                  Where is personInfo and what is it.
                  • 6. Re: Qs. about ValidationResult
                    Kurrykid Level 3
                    Check out the "Flex in a Week" training. They have a video and an exercise on validations...it pretty good and might help.

                    When all validators have passed, the length of the array you created with them should be equal to 0. It sounds like though with your situation that you are not sure how to check or validate a certain field...the Flex in a Week training will show you that.

                    If you need an example or I can help out further, drop me a line at: kurrykid at yahoo dot com.