javascriptextjssencha-touchsencha-touch-2dom-events

Sencha Touch: Enter key to submit form


I have a Sencha Touch code base and I wanted to be able to use the "Enter" key to submit the initial log in to the application instead of having to click the button on a desktop. Here is my Login view:

Ext.define('App.view.Login', {
    extend: 'Ext.form.Panel',
    alias: 'widget.login',

    requires:[
        'Ext.form.FieldSet',
        'Ext.field.Email',
        'Ext.field.Password'
    ],

    config: {
        items: [
            {
                xtype: 'toolbar',
                docked: 'top',
                title: 'App'
            },
            {
                xtype: 'fieldset',
                margin: '.5em .5em 1.5em',
                title: 'Login',
                items: [
                    {
                        xtype: 'emailfield',
                        name: 'email',
                        placeHolder: 'email@example.com',
                        required: true
                    },
                    {
                        xtype: 'passwordfield',
                        name: 'password',
                        placeHolder: 'password',
                        required: true,
                    }
                ]
            },
            {
                xtype: 'container',
                layout: {
                    type: 'vbox'
                },
                margin: '10px',
                items:[
                    {
                        xtype: 'button',
                        margin: '10px',
                        itemId: 'login',
                        text: 'Login'
                    }
                ]
            }
        ]
    }
});

And here is my Login controller:

Ext.define("App.controller.Login", {
    extend: "Ext.app.Controller",
    config: {
        views: ["Login", "user.Home"],
        stores: ["LoginInstance"],
        refs: {
            password: 'passwordfield[name="password"]',

            login: {
                autoCreate: true,
                selector: "login",
                xtype: "login"
            }
        },
        control: {
            password: {
                keyup: function(field, e) {
                    if(e.event.keyCode === 13) {
                        console.log('Do login');
                        this.onLoginTap();
                    }
                }
            },
            "login #login": {
                tap: "onLoginTap"
            },

            // ...

        }
    },

    onLoginTap: function() { ... } // do the login

However, this seems to not do anything (that is, not even the console.log appears in the console!). Does anyone have have suggestion as to what I could be doing wrong?


Solution

  • It looks like there's more than one issue in your code.

    I don't think this is exhaustive. There must be more issues.

    Please read the documentation and don't try to code by trial and error. It is not a good programming practice.