You could use the focusOut event instead.
The valueCommitted handler is going to fire before the component attempts to
change focus, so after it has executed (and you’ve called setFocus) THEN
the component will switch focus. So you need to switch focus back later in the
process.
Matt
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of cruegger2000
Sent: Thursday, September 08, 2005
12:43 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] setting
focus back to component that fails validation?
I create a form dynamically and need to do my data
validations
within ActionScript code. I generate a TextInput
component that
must be numeric. What I'd like to have happen is
that if the
user enters non-numeric data, I issue an alert;
when the user
clicks ok, the focus goes back to the TextInput
field that failed
validation. However, I can't get the focus to go
back to the
failed component (even if I dont issue an alert).
Code snippets
below, any ideas what I'm doing wrong?
Thanks in advance:
mxml snippet
<mx:TextInput id="item1"
valueCommitted="itemChanged(event)"/>
ActionScript:
var myValidator:NumberValidator = new
NumberValidator();
public function itemChanged(event): Void
{
var ok:Boolean =
NumberValidator.validateNumber(myValidator,
event.target.text,
null,
"text");
if (ok == false)
{
// Force focus to failed
component
event.target.setFocus();
}
}
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
YAHOO! GROUPS LINKS
|