Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Validator and Setting Focus

1 view
Skip to first unread message

Eduardo SIlveira

unread,
May 2, 2013, 9:44:04 AM5/2/13
to
I'm get today the way to setFocus() on the event target by Validator.

To use on Flex 3.0+ the validators you can try it.

<fx:Declarations>
<fx:Array id="arrValidadores">
<s:NumberValidator property="selectedIndex" minValue="0" source="{dplCadType}" required="true" triggerEvent="change"/>
<mx:StringValidator property="text" source="{txtName}" required="true" triggerEvent="change"/>
<mx:EmailValidator property="text" source="{txtEmail}" invalidCharError="Invalid Character!" invalidDomainError="Invalid Domain" missingAtSignError="Invalid Email"
</fx:Array>
</fx:Declarations>

<fx:Script>
<![CDATA[
import mx.validators.Validator;
protected function validateFields():void{
var arrError:Array = Validator.validateAll(arrValidadores);
if(arrErros.length > 0) {
arrErros[0].target.source.setFocus();
Alert.Show("Check the red field!");
}
]]>
</fx:Script>


Set the fields and use that function you will return the alert and set focus at the target was not validated.


0 new messages