2 Replies Latest reply on Mar 2, 2009 8:20 AM by PeakDigital

    Validation best practices?

    PeakDigital Level 1
      I'm still working on learning Flex, having previously worked in VB, ASP and PHP. Today I was working on a small form that needed to be validated. My specs are that all fields are required, and the submit button is to remain disabled until all fields are valid.

      In the past I have used a simple summing function to see how many fields in a form were valid; if less than the total field count then validation failed.

      Here is what I wrote in my Flex project. Is there a more efficient method that I should be using? Execution seems to be instant, but if this does not conform to "best practices" I'd like to know the alternative. Thank you for your input.

        • 1. Re: Validation best practices?
          Gregory Lafrance Level 6
          To me, you might be able to use binding to just have the button enabled property bound to a Boolean variable.

          Also have an ArrayCollection named validAC.

          private function handlerValidation(event:ValidationResultEvent, validatorName:String):void{
          submitBtn.enabled = numControls == (validAC.length);
          • 2. Validation best practices?
            PeakDigital Level 1

            Thank you for your advice. I understand the concept of binding the enabled property - and that would save a few lines of code, but I don't understand the syntax of the last line using both = and ==.

            I think I saw something like that once in my research but don't know what it's called so can't find any documentation.

            Thank you.