Results 1 to 6 of 6

Thread: How to get component object from click event(selected/clicked component in panel)

  1. #1
    Sencha Premium Member
    Join Date
    Jun 2012
    Posts
    41

    Default Answered: How to get component object from click event(selected/clicked component in panel)

    var mypanel=Ext.create("Ext.panel.Panel",{
    items: [{
    xtype: 'textfield', //clicked component
    fieldLabel: 'myname'
    }, {
    xtype: 'textfield',
    fieldLabel: 'myname1'
    }]

    })


    mypanel.el.on('click', function(e,el) {

    //Here i need to get 'myname' component object and get component config details


    });

  2. Try this:
    Code:
    mypanel.el.on('click', function(e,el) {
       var cmp = Ext.getCmp( el.id.replace(/-[a-z]+$/i, '') );
       console.log(cmp); 
    }

  3. #2
    Sencha User
    Join Date
    Dec 2011
    Posts
    10
    Answers
    1

    Default

    Do you mean something like this?
    Code:
    mypanel.el.on('click', function(e,el) {
    
    //Here i need to get 'myname' component object and get component config details
    Ext.get(el.id);
    
    });

  4. #3
    Sencha Premium Member
    Join Date
    Jun 2012
    Posts
    41

    Default

    Ext.get returns an Ext.Element object which is an abstraction of an HTML element object containing utility methods to perform DOM manipulation. It does not retrieve Components (e.g. Panels, Grids, form Fields, etc) by their id.

  5. #4
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    Try this:
    Code:
    mypanel.el.on('click', function(e,el) {
       var cmp = Ext.getCmp( el.id.replace(/-[a-z]+$/i, '') );
       console.log(cmp); 
    }

  6. #5
    Sencha Premium Member
    Join Date
    Jun 2012
    Posts
    41

    Default But I didn't provide any id or itemid for the component

    how the code return component object without provide any id or itemid for the component ?

  7. #6
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    The component id will be generated automatically by the framework if it does not exist. It is a good practice to not config id for component, try to use itemId instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •