I have created a component for grouping validators, which I have attached. It 
is not documented at the moment so I will do my best to explain below.

A validator group can be instantiated as an MXML component and contain 
validators:

<?xml version="1.0" encoding="utf-8"?>
<validators:ValidatorGroup
   xmlns:mx="http://www.adobe.com/2006/mxml";
   xmlns:validators="com.adobe.ac.validators.*">
   
   <validators:validators>

      <mx:TextValidator
         id="quantity1"
         required="true"
         source="{ field1 }"
         property="text" />  
      
      <validators:TextValidator
         id="quantity2"
         required="false"
         source="{ field2 }"
         property="text" />  

   </validators:validators>
      
</validators:ValidatorGroup>


It can also be used inside another component and contain groups:

<validators:ValidatorGroup id="validatorGroup">
      <validators:groups>
         <myValidators:ValidatorGroup1 
            id="validatorGroup1" />
         <myValidators: ValidatorGroup2
            id=" validatorGroup2" />
         <myValidators:ValidatorGroup3
            id=" validatorGroup3" />
         <myValidators:ValidatorGroup4
            id=" validatorGroup4" />
         <myValidators:ValidatorGroup5
            id=" validatorGroup5" />
      </validators:groups>
   </validators:ValidatorGroup>

As shown above a ValidatorGroup can contain other groups and validators so you 
could do something like this:

<validators:ValidatorGroup id="validatorGroup">
      <validators:groups>
         <myValidators:ValidatorGroup1 
            id="validatorGroup1" />
         <myValidators: ValidatorGroup2
            id=" validatorGroup2" />
         <myValidators:ValidatorGroup3
            id=" validatorGroup3" />
         <myValidators:ValidatorGroup4
            id=" validatorGroup4" />
         <myValidators:ValidatorGroup5
            id=" validatorGroup5" />
      </validators:groups>
        <validators:validators>

      <mx:NumberValidator
         id="quantity1"
         required="true"
         source="{ field1 }"
         property="text" />  
      
      <validators:NumberNewValidator
         id="quantity2"
         required="false"
         source="{ field2 }"
         property="text" />  

   </validators:validators>
 </validators:ValidatorGroup>


The component is written to be used in MXML and programmatically in AS.

The concept behind this was to allow validators to be bound to the model. As 
such there is a method (registerForValidationEvents) to register a field for 
validation events. For example if you had a wizard, the pages of the wizard may 
only be created when the user visits the page. So what happens if the user 
jumps to the last page (there maybe an accordion to jump between pages)? To do 
support this you need to validate against the model and not the views. Using 
this same example, you can create a ValidatorGroup per page - to validate per 
page - and create a ValidatorGroup to contain page groups to allow validation 
at a wizard level.

The ValidatorGroup has an isValid property.

Hopefully this provides enough info to use the component. I will document it 
and blog it at some point.




--- In [email protected], Luis Eduardo <[EMAIL PROTECTED]>
wrote:



  i was thinking on one ValidatorManager component that take care of a 
group of validators more easy and blackboxed.
  is there something like this?
  how u guys resolved this?

  my idea is something like this:

 <mx:ValidatorManager id="theJudge"/>

  <mx:StringValidator id="valString1" ...blablabla... />
  <mx:DateValidator id="valString2" ...blablabla... />
  <mx:EmailValidator id="valString3" ...blablabla... />

  and on the codes (probably on init() ) we make something like this:

  theJudge.addValidator( valString1 );
  theJudge.addValidator( valString2 );
  theJudge.addValidator( valString3 );

  at any point of the code we want test for all fields are valid we just 
could do:

  theJudge.validateAll()  -> to return a array of invalids validators 
like the function listed here ( 
http://livedocs.macromedia.com/flex/2/langref/mx/validators/Validator.html
)

  or perhaps a getter inside the judge that performs this to us and just 
answer the question "is there some punk out there?" and return just true 
and false like this:

  if ( theJudge.allValid ) {
  gogogo()
  }

  what u guys think of this? there are a better approach?

   waiting your replay,

               Luís Eduardo.

P.S.  i tryed the follow code:

<mx:Validator id="mainVal"/>
<mx:array id="valarray">
  <mx:StringValidator id="valString1" ...blablabla... />
  <mx:DateValidator id="valString2" ...blablabla... />
  <mx:EmailValidator id="valString3" ...blablabla... />
</mx:array>

and then on the codes:

mainVal.validateAll(valarray)  like the docs said i could do but...  it 
appear that this function do not exists "validateAll".



        

        
                
_______________________________________________________ 
Você quer respostas para suas perguntas? Ou você sabe muito e quer
compartilhar seu conhecimento? Experimente o Yahoo! Respostas !
http://br.answers.yahoo.com/

--- End forwarded message ---





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcomponents/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcomponents/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Attachment: ValidatorGroup.as
Description: ValidatorGroup.as

Reply via email to