Hi,
   I've got the solution now. I'll post it, if someone needs it in the
future:
In general: I've a ArrayCollection "validators" where I put all my
validators in (when I create them (dynamically)).

On creation of my FormItems (i.e. a TextInput called "editor"), I add
the following two EventListeners:
editor.addEventListener(Event.CHANGE, validateForm);
editor.addEventListener(Event.CHANGE, turnOnOneValidator);


Then my ActionScript functions for validation:

/**
  * validates all form elements. in allValid all return values from each
validation are boolean combined
  * (if a single element returns false, everything is false
  */
internal function validateForm():Boolean {
     var result:ValidationResultEvent = null;
     var allValid:Boolean = true;

     for(var i:Number=0; i<validators.length; i++) {
         result = validators.getItemAt(i).validate();
         if(result.results != null) {
             allValid = false;
             result = null;
         }
     }
     return allValid;
}

/**
  * disables all validators
  * simulates a ValidationResultEvent with VALID for each control (all
red borders will disappear)
  */
internal function turnOffValidators():void {
     for(var i:Number=0; i<validators.length; i++) {
         validators.getItemAt(i).enabled = false;
         var evt:ValidationResultEvent = new
ValidationResultEvent(ValidationResultEvent.VALID);
         validators.getItemAt(i).source.validationResultHandler(evt);
     }
}

/**
  * enables all validators
  */
internal function turnOnValidators():void {
     for(var i:Number=0; i<validators.length; i++) {
         validators.getItemAt(i).enabled = true;
     }
}

/**
  * turns on a specific validator (the one from event.target)
  * if there's a control changed and the input won't validate, it should
be marked with a red border,
  * event if the entire form has disabled validators
  */
internal function turnOnOneValidator(event:Event):void {
     for(var i:Number=0; i<validators.length; i++) {
         if(validators.getItemAt(i).source == event.target) {
             validators.getItemAt(i).enabled = true;
         }
     }
}

I hope, this may help someone too :-)

You've to play around, when to enable and disable your validators, but I
think, you'll get this!

Bye,
Fritz
--- In flexcoders@yahoogroups.com, "fritzdimmel" <[EMAIL PROTECTED]>
wrote:
>
> Hi.
> I've a form who's creation time is very long (complete dynamically).
> With this form I want to edit several datasets. If one dataset doesn't
> validate correctly and I want to edit another, or, let's say, create a
> new dataset (with empty values!) I don't want to have that any
> TextInput has a red border.
> I want to validate a "new" dataset when the "save" button is clicked.
>
> Do you understand?
>
> Thanks,
> Fritz
>
>
> --- In flexcoders@yahoogroups.com, "maunger" maunger@ wrote:
> >
> > Hey Fritz, what's the 'timing' on this?
> >
> > I mean, under what conditions do you want to disable the validation?
> >
> > Mitch
> >
> > --- In flexcoders@yahoogroups.com, "fritzdimmel" <fritz.dimmel@>
wrote:
> > >
> > > Hi!
> > > I've a form with many controls (TextInputs, ...) to validate.
> > > Everything works fine but I can't figure out, how to accomplish
this:
> > > I have, let's say, a TextInput, and the validation for this
returns
> > > false. The textinput gets a red border.
> > > Now I want to have a possibility to disable the validator
temporarliy.
> > > So that the red border disappears until I'm re-enabling the
validator.
> > >
> > > How can I do this?
> > > By setting Validator.enabled to false the red border (+ the error
> > > message) still exists.
> > >
> > > Thanks for any hints!
> > >
> > > Fritz
> > >
> >
>

Reply via email to