3

I have a controller and a TabPanel in Sencha Touch 2, I want to call a function when an element is tapped on the TabPanel:

TabPanel.js

Ext.define('app.view.principalTabPanel', {
    extend: 'Ext.tab.Panel',
    alias: 'widget.ptabpanel',
    config: {
        ui: 'light',
        items: [
            {
                xtype: 'container',
                itemId: 'idContnr',
                title: 'tap Me!',
                iconCls: 'bookmarks'
            }
        ],
        tabBar: {
            docked: 'bottom',
            ui: 'light'
        }
    }
});

controller.js

Ext.define('app.controller.mainController', {
    extend: 'Ext.app.Controller',
    config: {
        control: {
            "ptabpanel #idContnr": {
                tap: 'takePhoto'
            }
        }
    },
    takePhoto: function() {
        console.log('toma foto!'); // Not Working :(
    }
});
philg
  • 175
  • 1
  • 7
lito
  • 3,105
  • 11
  • 43
  • 71

3 Answers3

2

Instead of listening to 'tap' events on the tabs, you should listen to 'activeitemchange' on the tabpanel itself. See http://docs.sencha.com/touch/2-0/#!/api/Ext.tab.Panel-event-activeitemchange

borck
  • 928
  • 10
  • 19
1

It works when listening/Query for the html-id generated by Sencha "ext-tab-2".

for Instance:

config: {
    control: {
        "ptabpanel #ext-tab-2": {
            tap: 'onButtonTap'
        }
    }
},

But now the problem is how to change the "ext-tab-2" name generated by Sencha Touch 2

@Borck: thanks!.

lito
  • 3,105
  • 11
  • 43
  • 71
0

You can assign IDs to the tab bar buttons by adding this configuration to the tab panel:

tabBar: {
  id: 'myTabBar',
  items:[
    {
      id: 'myFirstTab'
    },
    {
      id: 'mySecondTab'
    },
    ...
   ]
 }
RThomas
  • 10,702
  • 2
  • 48
  • 61
Adam Klein
  • 401
  • 3
  • 10
  • myFirstTab and mySecondTab would be the IDs of the panels, not the buttons. With this, you can get the show or hide events in the controller. – prossel Apr 25 '14 at 08:34