Search code examples
javascriptextjssencha-touch-2

How to get Current Operating form in EXT JS


I have a request to submit a form on a press of ENTER button . I would like to customise it in such a way that it can be used anywhere throughout my application. So whenever i press enter after entering a field value. i can submit the current form. Is there a way to fetch the current form (without knowing form name or id) whenever a ENTER button is pressed on a particular field?


Solution

  • Ext.define('MyApp.overrides.Field',{
        override: 'Ext.form.field.Base',
        enableKeyEvents: true,
        listeners: {
            keyup: function(field, e) {
                var key = e.getKey(),
                if(key == 13) { // 13 = Enter key
                    var form = field.up('form');
                    if(form) form.submit();
                }
            }
        }
    });