Nilanchala
Nilanchala

Reputation: 5941

How to create UI components dynamically using Sencha touch?

I am a beginner to Sencha touch API. I am real struggling to make the UI components using Sencha touch lib. I have created some sample UI. But it is static in nature for now. How can i make it dynamic. Dynamic means i want my JSON response to decide the components to be added on the screen. How can i do this. Please help me.

Ext.setup({
    icon: 'icon.png',
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    glossOnIcon: false,

    onReady: function() {

        var form;

        var formBase = {
            scroll : 'vertical',            
            standardSubmit : false,
            items: [
                {
                    xtype: 'fieldset',
                    title: 'Login Screen',
                    instructions: 'Enter agent number and password to login.',
                    defaults: {
                        required: true,
                        labelAlign: 'left',
                        labelWidth: '45%'
                    },
                    items: [
                    {
                        xtype: 'textfield',
                        name : 'username',
                        label: 'Agent Number',
                        useClearIcon: true
                    }, {
                        xtype: 'passwordfield',
                        name : 'password',
                        label: 'Password',
                        useClearIcon: false
                    }]                   
                }],
            listeners : {
                submit : function(form, result){
                    console.log('success', Ext.toArray(arguments));
                },
                exception : function(form, result){
                    console.log('failure', result);
                }
            },

            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'bottom',
                    items: [
                        {
                            text: 'Exit',
                            ui: 'exit',
                            handler: function() {
                                  alert('Are you sure ?');                               
                            } 
                        },
                        {
                            text: 'Login',
                            ui: 'confirm',
                            handler: function() {
                                  alert('Login please wait..');
                            } 
                        }
                    ]
                }
            ]       
        };

        if (Ext.is.Phone) {
            formBase.fullscreen = true;
        } else {
            Ext.apply(formBase, {
                autoRender: true,
                floating: true,
                modal: true,
                centered: true,
                hideOnMaskTap: false,
                height: 385,
                width: 480
            });
        }

        form = new Ext.form.FormPanel(formBase);
        form.show();
    }
});

Upvotes: 2

Views: 5990

Answers (2)

Deepanshu Shukla
Deepanshu Shukla

Reputation: 133

Dyanmic forms from json file in sencha touch

check this link I have posted the solution for this .You just need to send xtype for the views through JSON .And whatever you want . I have also posted the json file and code to create dynamic view .hOpe it will help you

Upvotes: 0

ilija139
ilija139

Reputation: 2974

To add items to a panel use panel.items.add(list); and afterwards don't forget to call panel.doLayout();. See this question for example Calling the items.add method twice causes the two items to overlap on the card

Upvotes: 2

Related Questions