Search code examples
sencha-touchsencha-touch-2

Layout with Sencha Touch


Below is the code of a view in our project. I want a formpanel and a button in a vbox layout. I want to center the button horizontally.

Ext.define('Coder.view.membership.Login', {
    extend: 'Ext.Container',
    xtype: 'membershiploginview',

    requires: ['Ext.field.Password'],

    config: {
        title: 'Membership',
        layout: {
            type: 'vbox',
            align: 'center',
            pack: 'center'
        },
        items: [
            {
                xtype: 'formpanel',
                items: [
                    { xtype: 'textfield', name: 'userName', label: 'User ID' },
                    { xtype: 'passwordfield', name: 'password', label: 'Password' }
                ],
                height: 300,
                flex: 1
            },
            { xtype: 'button', text: 'Login' }
        ]
    }
})

With this configuration, the formpanel takes all available space vertically but none of the controls in it are visible. I can see the button centered horizontally where the formpanel ends. Why can't I see the controls in the formpanel?


Solution

  • In vbox layout:

    1. pack: center will placed items in the middle vertically.

    2. align: center will placed items in the middle horizontally.

    Your form panel didn't show up because you do not specify any width for your form so your form will obviously takes width: 100% as default, therefore your config align: center get conflict.

    To make it works, you should either remove that config or specify a width for your form panel.