0 Replies Latest reply on Jan 4, 2010 2:02 PM by WilliamCherry

    A better approach to validation

    WilliamCherry

      The way in which validators are implemented could be made much simpler and cleaner then it is currently implemented. Validators should be properties of the components that they validate. For example instead of:

       

      <?xml version="1.0"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009
                     xmlns:s="library://ns.adobe.com/flex/spark" 
                     xmlns:mx="library://ns.adobe.com/flex/halo">
      <fx:Declarations>
          <mx:EmailValidator source="{email}"                              
                             property="text"             
                             trigger="{submitButton}" 
                             triggerEvent="click"/>                                                
        </fx:Declarations>
        <s:TextInput id="email"/>                                           
        <s:Button label="Submit" id="submitButton"/>
      </s:Application>

       

      We are left with a much simpler and cleaner:

       

      <?xml version="1.0"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009
                     xmlns:s="library://ns.adobe.com/flex/spark" 
                     xmlns:mx="library://ns.adobe.com/flex/halo">
        <s:TextInput id="email">                                     
            <mx:Validator type="Email" trigger="{submitButton}"/>
        <s:/TextInput>
        <s:Button label="Submit" id="submitButton"/>
      </s:Application>

       

      This contains fewer lines and the intent of the code is made much clearer.