thanks all for the help so far!
the solution of Pablo works for me. although I also have the problem
with CTRL+V. If the user inputs a string like that there is no
cancelKey() possible.
I added a second keyhandler doing this:
inputRufnummer.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
if
(!inputRufnummer.getText().matches("[0-9]*")) {
sendButton.setEnabled(false);
sendButton.setText("Not a number");
} else {
sendButton.setEnabled(true);
sendButton.setText("Send");
}
}
});
Best solution for me would be if the framework would offer a "number
only" TextBox - but for the moment this solution must suffice.
On Jun 30, 12:50 am, Thomas Broyer <[email protected]> wrote:
> On 29 juin, 22:38, Eric <[email protected]> wrote:
>
>
>
> > On Jun 29, 3:20 pm, Thomas Broyer <[email protected]> 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 [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
-~----------~----~----~----~------~----~------~--~---