Devmix
Devmix

Reputation: 1868

How to fire click event using cards?

I'm working with 2 panels using cards. If I click on "Go to first" it takes me to First Panel and if I click on "Go to second" it takes me to the Second Panel. This works great!

"This is the first panel message-recieved"

Can anyone tell me what I'm missing in my code? So far I'm firing the click event inside the boxready event, but it will only get called once page loads and after that I cannot call sendMessage anymore.

Code snippet:

listeners: {
    boxready: function (cmp) {
        cmp.down('[name=someButton]').fireEvent('click', me.sendMessage());
    }
}

LIVE DEMO

Upvotes: 1

Views: 281

Answers (3)

Narendra Jadhav
Narendra Jadhav

Reputation: 10262

As you are using card layout so you need to use activate event for child component of card panel.

  • activate

    Fires after a Component has been visually activated.

    Note This event is only fired if this Component is a child of a Ext.container.Container that uses Ext.layout.container.Card as it's layout or this Component is a floating Component.

In this Fiddle, I have used your code and put modification with activate event on child components.

Code snippet:

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.application({
            name: 'Fiddle',

            launch: function () {
                var me = this,
                    sendMessage = function (msg) {
                        alert('message-recieved from : ' + msg);
                    };

                Ext.create('Ext.panel.Panel', {
                    renderTo: Ext.getBody(),
                    height: 400,
                    bodyPadding: 10,
                    title: 'Card Layout Example',
                    layout: 'card',
                    defaults: {
                        listeners: {
                            activate: function (panel) {
                                sendMessage(panel.msg);
                            }
                        }
                    },
                    items: [{
                        xtype: 'panel',
                        title: 'First',
                        msg: 'This Panel one activated',
                        html: 'This is the first panel'
                    }, {
                        xtype: 'panel',
                        title: 'Second',
                        msg: 'This Panel two activated',
                        html: 'This is the second panel'
                    }],
                    dockedItems: [{
                        xtype: 'toolbar',
                        dock: 'bottom',
                        items: [{
                            text: '<- Go to first',
                            name: 'someButton',
                            handler: function (button) {
                                var panel = button.up('panel');
                                panel.layout.setActiveItem(0);
                            }
                        }, '->', {
                            text: 'Go to second ->',
                            handler: function (button) {
                                var panel = button.up('panel');
                                panel.layout.setActiveItem(1);
                            }
                        }]
                    }]
                });
            }
        });

    }
});

Upvotes: 1

Chintan Kukadiya
Chintan Kukadiya

Reputation: 784

You have to add listeners in panel instead of box.

You can see here: Live Demo

Code snippet:

items: [{
    xtype: 'panel',
    title: 'First',
    html: 'This is the first panel',
    listeners: {
        show: function () {
            me.sendMessage(this.initialConfig.html);
        },
        render: function () {
            me.sendMessage(this.initialConfig.html);
        }
    }
}, {
    xtype: 'panel',
    title: 'Second',
    html: 'This is the second panel'
}]

Upvotes: 0

Rohit Sharma
Rohit Sharma

Reputation: 1410

Have a look at this fiddle.

Code snippet:

{
    xtype: 'panel',
    title: 'First',
    itemId: 'firstPanel',
    html: 'This is the first panel',
    listeners: {
        activate: function (cmp) {
            cmp.up('panel').down('[name=someButton]').fireEvent('click', me.sendMessage());
        }
    }
}

Upvotes: 0

Related Questions