Search code examples
sencha-touch-2enter

how to submit a login form with enter key in sencha touch


I am using Sencha Touch. I would like to login with pressing ENTER key in my key board.Can any one please know the answer please help.

Here is my code.

Ext.define('App.form.LoginForm', {
    extend: 'Ext.form.Panel',
    xtype: 'loginform',
    id: 'loginform',
    config: {
        items: [{
            html: '<br><div style="text-align:center;"><i class="fa fa-lock fa-5x icon-fill"></div>'
        },{
            xtype: 'fieldset',
            items: [{
                xtype: 'textfield',
                id: 'username_fld',
                name: 'username_fld',
                required: true
            }, {
                xtype: 'passwordfield',
                id: 'password_fld',
                name: 'password_fld',
                placeHolder: 'Password',
                required: true
            }]
        }, {
            xtype: 'button',
            name: 'login_btn',
            itemId: 'logInButton',
            text: 'Log In',
            cls: 'x-form-fieldset'
        }]
    }
});

Solution

  •          {  
                xtype: 'passwordfield',
                id: 'password_fld',
                name: 'password_fld',
                placeHolder: 'Password',
                required: true,
                listeners: {
                    painted: function (field, e) {
                        document.addEventListener("keydown", myFunction, false);
                    }
                }              
              }
    
    
    
    
    
     function myFunction(evt)  {  
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode == 13) { // charcode 13 for "entry" keyboard
            evt.preventDefault();
            var myApp = me.getApplication().getController('App');
            myApp.login()
         }
     }