1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
    greenkey_loman is on a distinguished road

      0  

    Default Answered: tap event on a dinamically created custom Panel (MVC)

    Answered: tap event on a dinamically created custom Panel (MVC)


    Hi coders, I have a problem about views and events.

    I have to put dinamically some custom Panels in my app (xtype:'card').

    I want my Controller to manage events on these Panels, with "refs".

    Sample code:

    Code:
    Ext.define('D45.controller.Deck', {
        extend: 'Ext.app.Controller',
        config: {
        ...
            refs: { 
                    desk: '#desk',
                 card: 'card'
            },
            control: {
                    card:{
                    tap: function(){
                        Ext.Msg.alert('tap!');
                    }
                },
        ...
        putCard: function(id){
                 this.getDesk().add({ xtype:'card', cardNo:id });
        }
    });
    The event simply doesn't work!
    Have you got some ideas?

  2. refs only support a single instance.

    Like I said, you can easily add a tap event to the panel's element and then have it listenable in the controller. Here is an example:

    Code:
    Ext.define('Test.controller.Main', {
        extend : 'Ext.app.Controller',
    
        config : {
            control : {
                'test-mypanel' : {
                    tap : 'onPanelTap'
                }
            }
        },
    
        onPanelTap : function(panel) {
            console.log('panel was tapped on', panel);
        }
    });
    
    Ext.define('Test.view.MyPanel', {
        extend : 'Ext.Panel',
        xtype  : 'test-mypanel',
    
        initialize : function() {
            this.callParent(arguments);
    
            this.relayEvents(this.element, ['tap']);
        }
    });
    
    Ext.application({
        name : 'Test',
    
        controllers : [
            'Main'
        ],
    
        launch : function () {
    
            Ext.Viewport.setActiveItem({
                xtype : 'test-mypanel',
                html  : 'Tap on me and look at the console'
            });
    
        }
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    In the API docs does the component list a tap event? If not, why did you think it'd work? You can fire the event from the view as you would need to add an element event listener.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
    greenkey_loman is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    In the API docs does the component list a tap event?
    Yep!
    Code:
    Ext.define('D45.view.Card', {
        extend: 'Ext.Panel',
        xtype: 'card',
        ...
    Quote Originally Posted by mitchellsimoens View Post
    If not, why did you think it'd work? You can fire the event from the view as you would need to add an element event listener.
    It's difficult to post all the code because it covers some files...

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Ext.Panel does not have a tap event listed in the API docs.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
    greenkey_loman is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Ext.Panel does not have a tap event listed in the API docs.
    Oh... I feel stupid...
    but...
    I changed "
    extend: 'Ext.Panel',
    " into "
    extend: 'Ext.Button',
    "... nothing changed!

    Also if i use this:
    D45.app.getController('Deck').getCard()
    It returns only one "Card"... i expected to return an Array of Cards...

    And if I set an event on it:
    D45.app.getController('Deck').getCard().onTap(function(a){alert(a);})
    It doesn't work.

    What am I doing wrong?

  7. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      1  

    Default


    refs only support a single instance.

    Like I said, you can easily add a tap event to the panel's element and then have it listenable in the controller. Here is an example:

    Code:
    Ext.define('Test.controller.Main', {
        extend : 'Ext.app.Controller',
    
        config : {
            control : {
                'test-mypanel' : {
                    tap : 'onPanelTap'
                }
            }
        },
    
        onPanelTap : function(panel) {
            console.log('panel was tapped on', panel);
        }
    });
    
    Ext.define('Test.view.MyPanel', {
        extend : 'Ext.Panel',
        xtype  : 'test-mypanel',
    
        initialize : function() {
            this.callParent(arguments);
    
            this.relayEvents(this.element, ['tap']);
        }
    });
    
    Ext.application({
        name : 'Test',
    
        controllers : [
            'Main'
        ],
    
        launch : function () {
    
            Ext.Viewport.setActiveItem({
                xtype : 'test-mypanel',
                html  : 'Tap on me and look at the console'
            });
    
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

  8. #7
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
    greenkey_loman is on a distinguished road

      0  

    Default


    Great!
    So the key is the function "relayEvents".

    Thank you very much!

Thread Participants: 1

Tags for this Thread