Results 1 to 7 of 7

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

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
      0  

    Default 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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1381
      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 @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
      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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1381
      0  

    Default

    Ext.Panel does not have a tap event listed in the API docs.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
      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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1381
      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 @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  8. #7
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
      0  

    Default

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

    Thank you very much!

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
  •