views:

14

answers:

1

I have a simple String validator like;

<mx:StringValidator property="text" source="{_codeInput}" enabled="true" minLength="2" required="true" />

And it works fine. The problem is how can I activate the required red border on a button click like "ADD" so that the user sees that this field is required.

alt text

Right now how it works is that once you enter a text, and deletes it the red border gets activated.

So is there a way to activate the red border on an action, before having to enter something and deleting it from a TextInput?

+2  A: 

Yep. By providing trigger and triggerEvent properties of Validator object. Something like this:

<mx:StringValidator property="text" source="{_codeInput}" enabled="true"
    minLength="2" required="true" trigger="{triggerButton}" triggerEvent="click"/>
<mx:Button id="triggerButton" label="ADD"/>

This way validation process should execute on Button click event. Unfortunately (?) it will prevent the default 'focusOut' behavior of your Validator.

Alternatively you can do something like this:

<mx:Array id="validators">
    <mx:StringValidator property="text" source="{_codeInput}" enabled="true"
        minLength="2" required="true" />
</mx:Array>
<mx:Button id="triggerButton" label="ADD"
    click="{Validator.validateAll(validators)}"/>

And you'll get validation both on focus out and button click.

2DH
thank you @2DH .
Adnan
Even better. Thanx again.
Adnan