My use case:
I have a TextBox which I want to validate onBlur. If validation fails,
I want to setFocus on it again. Which makes onBlur fire again, hence
the validation routine runs again (not ideal, in fact, a defect in my
mind).
My code:
== snip ==
public void onBlur(BlurEvent event) {
TextBox tb = (TextBox) event.getSource();
try {
Long longValue = Long.valueOf(tb.getText());
} catch (NumberFormatException e) {
// warn the user in the UI
// set the focus back on the TextBox
tb.setFocus(true);
}
}
== end snip ==
The onBlur is running again because FocusWidget does this:
== snip ==
public void setFocus(boolean focused) {
if (focused) {
impl.focus(getElement());
} else {
impl.blur(getElement());
}
}
== end snip ==
So, when I insert non-digits in my text box, and tab or click into the
next form element, onBlur fires once. In my catch block, I set the
focus again, which triggers onBlur again because of how
FocusWidget.setFocus is implemented.
This defect prevents me from displaying a message to the user just
once (ie, with an alert) or setting and clearing a message on fail/
pass of the validation.
Anyone have a workaround?
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.