PDA

View Full Version : How to click on the bottun with key?



parsbin
8 Nov 2011, 2:26 AM
Hi
i want to submit a from with press Enter.
i can focus on that bottun with this code

Ext.getCmp('login').focus();
but i can`t submit that after focus.
i can do this work with Extjs3 with this code:

Ext.getCmp('login').fireEvent("click", Ext.getCmp('login'));
but it does`t work in Extjs4
how can do this?

tobiu
8 Nov 2011, 8:45 AM
IMHO the better approach is to submit a form when a user presses enter inside a field.
To do this, you need to set the field-config:



enableKeyEvents : true


add a listener to the field on keypress and check if it was enter. you can set the config + listener using defaults or better fieldDefaults if you want this for all fields of your form.

parsbin
8 Nov 2011, 10:09 PM
thanks
but i can focus on the bottun but this code.
but the submit ket code does n`t work.


loginform.mon(loginform.el, {
keypress : function(e, t, opts) {
if (e.getKey() == e.ENTER) {
Ext.getCmp('login').focus();
Ext.getCmp('login').fireEvent("click", Ext.getCmp('login'));
}
}
});

parsbin
11 Nov 2011, 10:11 PM
not any idea?

slemmon
11 Nov 2011, 10:25 PM
Can you use the specialkey event?
You can see an example at:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text-event-specialkey

parsbin
11 Nov 2011, 11:28 PM
yes
i can receive answer after click on Enter key
this line of my codes not worked.
this is my just problem

Ext.getCmp('login').fireEvent("click", Ext.getCmp('login'));

i want submitted a button in listener of keypress event.

slemmon
12 Nov 2011, 6:42 AM
Do you have a click listener on 'login'?

listeners: {
click: function (btn) {
console.log('Login clicked')
}
}