Extjs Simulate Tab On Enter Keypress
I know it is not the smartest idea, but I still have to do it. Our users want to use ENTER like TAB. So, the best I came up with is this: Ext.override(Ext.form.field.Base, {
Solution 1:
In the past I've attached the listener to the document, something like this:
Ext.getDoc().on('keypress', function(event, target) {
// get the form field componentvar targetEl = Ext.get(target.id),
fieldEl = targetEl.up('[class*=x-field]') || {},
field = Ext.getCmp(fieldEl.id);
if (
// the ENTER key was pressed...event.ENTER == event.getKey() &&
// from a form field...
field &&
// which has valid data.
field.isValid()
) {
// get the next form fieldvar next = field.next('[isFormField]');
// focus the next field if it existsif (next) {
event.stopEvent();
next.focus();
}
}
});
Solution 2:
For Ext.form.field.Text and similar xtypes there is a extra config enableKeyEvents
that needs to be set before the keypress/keydown/keyup events fire.
The enableKeyEvents
config option needs to be set to true as it's default to false.
Solution 3:
Disclaimer: I'm not an expert on ExtJs.
That said, maybe try something like:
if (e.getKey() === 13) {
me.blur();
returnfalse; // cancel key event to prevent the [Enter] behavior
}
Solution 4:
You could try this
if (e.getKey() === 13) {
e.keyCode = Ext.EventObject.TAB
this.fireEvent(e, {// any additional options
});
}
Haven't really tried this ever myself.
Post a Comment for "Extjs Simulate Tab On Enter Keypress"