On 29 juin, 22:38, Eric <erjab...@gmail.com> wrote:
> On Jun 29, 3:20 pm, Thomas Broyer <t.bro...@gmail.com> wrote:
>
> > Note that "((TextBox) event.getSource()).cancelKey();" is exactly
> > equivalent to "event.preventDefault();"
>
> > ..and I believe the "// TODO(ECC) must be tested." really means that
> > it *needs* to be tested (i.e. I'm almost sure that it isn't enough;
> > I'm almost sure you also have to deal with KeyDown and/or KeyUp).
>
> How could I write my application to recover nicely when the user
> pastes
> alphabetic characters into the text box?  If the user selects Ctrl (or
> Cmd)-V,
> or right-clicks and pastes. the browser will not invoke the keyboard
> handler.
> I found out that IE has an onpaste event, but that isn't universal.

That's why I think "canceling keys" is not good practice (or at least
not good enough), you should instead (or in addition, if you really
want) either flag the field as invalid or automatically fix it (e.g.
on KeyUp field.setText(fix(field.getText()) where fix() does something
like a replaceAll("[^0-9]", "")).

The best solution, of course, would be to use an <input type=number>
in an HTML5-aware browser (Opera for now). But in the mean time, a
validation framework, or auto-correction work pretty well (and
cancelling keys are just a "bonus" if you can get it to work)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to