TextField events and formatting


I’m able to use the
to remove all the non-numeric characters of the
, but, like the
, it works only when the user presses Enter or when the cursor focus is changed.

How could it trigger an event when a key is pressed, for example? Something like the JavaScript events, perhaps…?

Also, is there any way to do some kind of masking? It would be great for example in telephone or currency fields.

Thanks in advance for the help.


There is currently no such functionality, but it’s planned, for instance:

Also, I made a IntegerField -example for a ‘how to make a new widget’ session I held some time ago, maybe you could make your own component that allows exactly the input you want:
Demo: http://marc.virtuallypreinstalled.com/example/integerfield
The server side: http://marc.virtuallypreinstalled.com/IntegerField.java
The client side: http://marc.virtuallypreinstalled.com/IIntegerField.java

Best Regards,

You can easily extend both server side and client side TextField. If you extend, then all you need is few lines off gwt-code (example add keyboardlistener and allow your format only)!

We have done a special TextField for numerical values only in the way that “Anonymous” suggestes. We have a normal textfield with addKeyboardListener(new KeyboardListenerAdapter(){… (gwt specific code) and in onKeyPress(…) we check the keycode and compare it to the legal keycodes we specified. ITextField.cancelKey() is run if the keycode is something that we don’t want exactly for that position.

This results to that nothing happens when you press, say, a letter or a decimal more than once.

…I just thought I’d point out that that is exactly what the example I linked above does…

Ah, really sorry Marc, I just skimmed through the thread and noticed only the masked input and superimmediate functionality plans from your reply. I should really pay more attention before posting replies :wink:

Thank you all. I will investigate the given examples and then I’ll try something.