View Full Version : Triggering of Events.KeyUp only on visible characters
jraue
16 Oct 2008, 3:41 AM
Hi,
we are frequently using
gxtTextField.addListener(Events.KeyUp, new Listener<FieldEvent>() {
public void handleEvent(final FieldEvent be) {
// Handle field change
}
});
constructs to check for changes in fields.
Unfortunately, the KeyUp event is also raised if no text has been modified, e.g. if arrow-left or home is pressed. Wouldn't it be better not to raise events for these non-modifying keys?
If not, how can I check for 'real' keys - there is no keyCode sent along?
Thanks,
Joachim
jraue
12 Jan 2009, 4:11 AM
Since the issue persists, I'd like to raise again the question if ignoring non-modifying keys would be more meaningful way of dealing with events. Maybe as an option at least?
Thanks,
Joachim
jraue
12 Jan 2009, 4:13 AM
For reference, the following can be used as a workaround until then:
@Override
public void onComponentEvent(ComponentEvent ce) {
if (ce.type == Event.ONKEYDOWN || ce.type == Event.ONKEYUP) {
final int keyCode = ce.event.getKeyCode();
switch (keyCode) {
case 9: // Tab
case 16: // Shift
case 17: // Ctrl
case 18: // Alt
case 33: // PgUp
case 34: // PgDn
case 35: // End
case 36: // Home
case 37: // Cursor Left
case 38: // Cursor Up
case 39: // Cursor Right
case 40: // Cursor Down
return;
}
}
super.onComponentEvent(ce);
}
Events.KeyUp fires for any key. There is no reason to change this.
What you are looking for is Events.Change. It is stated in the docs:
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/TextField.html
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/Field.html
jraue
12 Jan 2009, 4:30 AM
Thanks, Sven, I looked at Events.KeyUp, but it only fires when the focus is moved away from the TextBox, which is too late for me (I want to enable a Save button when text is entered into a field).
Am I right assuming that my workaround is the only option I have then?
So you want to validate the value with a custom method? Than you could use a custom validator:
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/TextField.html#setValidator(com.extjs.gxt.ui.client.widget.form.Validator)
jraue
10 Mar 2009, 4:29 AM
Thanks for the tip, that works along with setAutoValidate(true).
The only caveat persisting is that it remains undetected when something is pasted through right-click - paste. I guess I need to add a listener for Change in addition in order to detect that... :(
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.