I believe what you want to do is use the trigger and triggerEvent
properties of your NumberValidator, then use the NumberValidators valid
and invalid events to do the work. To try this remove the event
handling from your existing code and try the following
<mx:NumberValidator source="{testTXT}" property="text" minValue="1"
maxValue="99" trigger="{testTxt}" triggerEvent="change" valid="testA()"
invalid="testB()"/>
Also worth noting is that Flex has a really great built-in ability to
show the error information with the invalid field. To check this out try
public function testA():void{
testTxt.errorString = "";
}
public function testB():void{
testTxt.errorString = "The number must be between 1 and 99";
}
hth
Scott
Scott Melby
Founder, Fast Lane Software LLC
http://www.fastlanesw.com
greenfishinwater wrote:
I have a form with a few TextInput components. I have a TextInput with
a NumberValidator as one of the form items. On this TextInput I have
coded the valid and invalid events to populate other fields depending
on what has been entered. My experience is that the valid event is not
working correctly.
I have this sample code to illustrate:
in the first field enter 10, the valid event does not fire
in the first field enter 200, the invalid event fires correctly.
in the first field enter 10, the valid event does work now
in the first field enter 20, the valid event does not fire.
Any ideas. What I want is a way to fire an event after the validator
has completed, the valueCommit and FocusOut seem to fire before the
validator has completed.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml>"
layout="absolute">
<mx:Script><![CDATA[
private function testA():void {
msgTXT.text = "Valid: " + testTXT.text;
}
private function testB():void {
msgTXT.text = "Invalid: " + testTXT.text;
}
]]></mx:Script>
<mx:NumberValidator source="{testTXT}" property="text" minValue="1"
maxValue="99"/>
<mx:VBox>
<mx:Form>
<mx:FormItem label="Integer">
<mx:TextInput id="testTXT" valid="testA()" invalid="testB()"/>
</mx:FormItem>
<mx:FormItem label="Message">
<mx:TextInput id="msgTXT" editable="false" width="160"/>
</mx:FormItem>
</mx:Form>
</mx:VBox>
</mx:Application>
Thanks
Andrew