Hi Ray,
On Wednesday 01 July 2009 Raymond Cote wrote:
> I have a TextField which I'd like to limit to accepting only digits.
>
> I've added a listener to the TextField and can grab each keystroke as it
> is entered.
>
> However, I'm unclear as to how I could decide whether or not to let this
> keystroke through.
> The TextField is not being updated until after I receive the keystroke,
> so I suspect there's something I can do to say "not this keystroke."
Here's a little snippet that does the job:
--snip--
t = new qx.ui.form.TextField("");
this.getRoot().add(t);
t.addListener("keypress", function(e){
if(e.getKeyIdentifier().search(/[0-9]/) == -1) {
e.preventDefault();
}
});
--snip--
The magic line is the one with the "preventDefault" method. This way you tell
the browser to not perform the default behaviour. In our case here it is to
fill the textfield with the pressed key.
cheers,
Alex
------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel