Ext makes it extremely simple to listen for particular user actions, such as clicking on an element or pressing a particular key.
A common task would be listening for the Enter key to be pressed, and then submitting the form. So let's see how this is accomplished:
{ xtype: 'textfield', fieldLabel: 'Title', name: 'title', allowBlank: false, listeners: { specialkey: function(f,e){ if (e.getKey() == e.ENTER) { movie_form.getForm().submit(); } } } }
The specialkey
listener is called whenever a key related to navigation is pressed. This listener is also called every time the arrow keys are pressed, along with Tab, Esc, and so on. That's why we have to check to see if it was the Enter key before we take action.
Now the form will only be submitted when you press Enter.