Results 1 to 2 of 2

Thread: How to add a container dynamically and working? Maybe a bug?

  1. #1
    Sencha User
    Join Date
    May 2009
    Posts
    5
    Answers
    1
    Vote Rating
    1
      1  

    Default Answered: How to add a container dynamically and working? Maybe a bug?

    It's a simple question, i think, but I don't be able to add an object dynamicaly.
    Here the simplified working code to add statically:

    Code:
    Ext.application({
        name: 'Test',
        launch: function() {
            var applicationPanel = Ext.create('Ext.Panel', {
                fullscreen: true,
                layout: {
                    type: 'fit',
                },
                items: [{
                    xtype: 'container',
                    layout: {
                        type: 'hbox',
                        align: 'middle',
                    },
                    defaults: {
                        xtype: 'button',
                        flex: 1,
                        margin: 10,
                    },
                    items: [
                        {text: 'normal'},
                        {ui: 'round', text: 'round'},
                        {ui: 'small', text: 'small'},
                    ],
                }],
            });
        }
    });


    This code works, but I need to load items dynamically, for example moving out in a create block:

    Code:
    var buttonsPanel = Ext.create('Ext.Panel',{
        layout: {
            type: 'hbox',
            align: 'middle',
        },
        defaults: {
            xtype: 'button',
            flex: 1,
            margin: 10,
        },
        items: [
            {text: 'normal'},
            {ui: 'round', text: 'round'},
            {ui: 'small', text: 'small'},
        ],
    });
    Ext.application({
        name: 'Test',
        launch: function() {
            var applicationPanel = Ext.create('Ext.Panel', {
                fullscreen: true,
                layout: {
                    type: 'fit',
                },
            });
            applicationPanel.add([buttonsPanel]);
        }
    });

    ... or in a define block:

    Code:
    Ext.define('Test.Panel', {
        extend: 'Ext.Panel',
        config: {
            layout: {
                type: 'hbox',
                align: 'middle',
            },
            defaults: {
                xtype: 'button',
                flex: 1,
                margin: 10,
            },
            items: [
                {text: 'normal'},
                {ui: 'round', text: 'round'},
                {ui: 'small', text: 'small'},
            ],
        }
    });
    var buttonsPanel = Ext.create('Test.Panel');
    Ext.application({
        name: 'Test',
        launch: function() {
            var applicationPanel = Ext.create('Ext.Panel', {
                fullscreen: true,
                layout: {
                    type: 'fit',
                },
            });
            applicationPanel.add([buttonsPanel]);
        }
    });
    

    Every these two ways seems to works, because they display the buttons, but incredibly the buttons don't works and they are uncliccable!?
    It's seems a bug, but it't first time I try with Sencha Touch 2, so maybe I'm in wrong somewhere... where? Thanks all!

  2. Don't use Ext.create outside of Ext.application (or Ext.setup):

    Code:
    Ext.define('Test.Panel', {
        extend: 'Ext.Panel',
        config: {
            layout: {
                type: 'hbox',
                align: 'middle'
            },
            defaults: {
                xtype: 'button',
                flex: 1,
                margin: 10
            },
            items: [
                {text: 'normal'},
                {ui: 'round', text: 'round'},
                {ui: 'small', text: 'small'}
            ]
        }
    });
    
    Ext.application({
        name: 'Test',
        launch: function() {
            var applicationPanel = Ext.create('Ext.Panel', {
                fullscreen: true,
                layout: {
                    type: 'fit'
                }
            });
    
            var buttonsPanel = Ext.create('Test.Panel');
            applicationPanel.add(buttonsPanel);
        }
    });

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,413
    Answers
    3898
    Vote Rating
    1269
      0  

    Default

    Don't use Ext.create outside of Ext.application (or Ext.setup):

    Code:
    Ext.define('Test.Panel', {
        extend: 'Ext.Panel',
        config: {
            layout: {
                type: 'hbox',
                align: 'middle'
            },
            defaults: {
                xtype: 'button',
                flex: 1,
                margin: 10
            },
            items: [
                {text: 'normal'},
                {ui: 'round', text: 'round'},
                {ui: 'small', text: 'small'}
            ]
        }
    });
    
    Ext.application({
        name: 'Test',
        launch: function() {
            var applicationPanel = Ext.create('Ext.Panel', {
                fullscreen: true,
                layout: {
                    type: 'fit'
                }
            });
    
            var buttonsPanel = Ext.create('Test.Panel');
            applicationPanel.add(buttonsPanel);
        }
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •