Here's how I would do it:
<mx:Model id="person">
<name>
<custName>
<first>{firstInput.text}</first>
<middle>{middleInput.text}</middle>
<last>{lastInput.text}</last>
</custName>
</name>
</mx:Model>
<mx:TextInput id="firstInput"/>
<mx:TextInput id="middleInput"/>
<mx:TextInput id="lastInput"/>
<mx:Validator source="{person}" property="custName.first"
listener="{firstInput}" trigger="{btn}" triggerEvent="click"
required="true" />
<mx:Validator source="{person}" property="custName.middle"
listener="{middleInput}" trigger="{btn}" triggerEvent="click"
required="true" />
<mx:Validator source="{person}" property="custName.last"
listener="{lastInput}" trigger="{btn}" triggerEvent="click"
required="true" />
<mx:Button id="btn" label="Validate" />
So you basically have separate validators for each of the fields and
they all get triggered on the button click.
On 4/23/07, Kenneth Sutherland <[EMAIL PROTECTED]> wrote:
>
>
>
>
> Not sure if this wasn't answered as it's a bit difficult or because I posted
> it on a Friday J so I'm giving it another go, this time on a Monday.
>
> Cheers.
>
>
>
> ________________________________
>
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Kenneth Sutherland
> Sent: 13 April 2007 16:05
> To: [email protected]
> Subject: [flexcoders] validating multiple fields
>
>
>
>
>
>
>
> I've been following this example on livedocs
>
> http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001773.html
>
> for how to validate multiple fields. I can it to work apart from the
> setting of the actual errorString on the appropriate input box.
>
> I.E if I have three input boxes and box three has the error, then in the
> example from livedocs it puts the error around whatever box I declared as
> the listener. How do I put the error around the appropriate box? Any of
> the 3 boxes could have an error.
>
> When debugging I can see that there is a property called actualListeners
> which is an array, but its read only and the listener property only takes a
> Object. I have a work around for this which passes in the form that I'm
> validating to the custom validator then overriding the 'get
> actualListeners()' function, but I'm sure that there must be a better way of
> doing this.
>
>
>
> Thanks
>
> Kenneth.
>
>