2 Replies Latest reply on Oct 4, 2011 9:57 AM by jfb00

    Help with clean string validator

    jfb00 Level 3

      Hi,

      I have a custom funtion for form validation at the time of submit.

      If i submit more than once, the red tag displaying the error show multiple times.

      I try to reset errorString on the component but still display the error multiple times.

      In the stringValidator i found a property as array "errorArray=[]", it collects the error.

      I am creating a new string validator every time i call the function as: var sv:StringValidator = new StringValidator() i don't know why is not deleting the array.

      It is a way to reset this array?

      I try to do a reference as sv.source.errorArray, but every time I got an error:

      Property errorArray not found on mx.controls.TextInput and there is no default value.

      Please help.

       

      Johnny

        • 1. Re: Help with clean string validator
          Filmzaddict

          I cant tell whats wrong, but I usually avoid using the Form component and create a custom component serving as a form. Lets assume there are a bunch of controls on it, a submit button, and label with an id "warning". Then inside the click handler for submit button you can do something like this:

           

          private function submitClickHandler(e:MouseEvent):void

                                        {

                                                  if (validate())

                                                  {

                                                            //do something after everything had been validated

                                                  }

                                        }

           

                                        private function validate():Boolean

                                        {

                                                  var result:Boolean = true;  //lets asume everything is okay

           

                                                  //now validate every control as you see fit:

                                                  if (someLabel.Text == "")

                                                  {

                                                            result = false;

                                                            warning.text = "* Please fill out someLabel";

                                                  }

           

          ...

          ...

           

                                                  if (result == true)

                                                            warning.text = "";

           

                                                  return result;

                                        }

          • 2. Re: Help with clean string validator
            jfb00 Level 3

            Thanks for you reply and help.

            I have the same logic but I like how flex can show a message in the component an highlight in red. Also i do this not only for text, i do it for combo and other components.

            What I do is instead of the if (someLabel.Text == "") i do check with a custom function if (myCustomFunction(someText,"", 0) == false){result= false;};

            I found a temporary way, just add the error message after is coming back from the custom function but I would like to take care this in the function.

            Rgds

             

            Johnny