Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs HTML Component Click Event

I have built a custom HTML component in extJS by specifying the html value of a panel. I am unable to attach the event handlers to the element (or they are somehow not firing). However, I am able to do other things on the component like hide, append etc.

Ext.select('#toFieldDiv').on('click',function() {
    alert("something");
});  //Doesn't Work

Ext.select('#toFieldDiv').hide('slow');  //Works

Any idea?

Here is my component definition:

{
    xtype: 'panel',
    x: 70,
    y: 0,
    html: "<div id=\"toFieldDiv\" class=\"to-field\"> </div>"
}

I have even tried the same with jQuery. Again the hide works, but not the click.

like image 918
Pulkit Goyal Avatar asked Oct 15 '11 16:10

Pulkit Goyal


1 Answers

I found an example and explanation of why this doesn't work out of the box on the Sencha forums. I implemented a suggested solution below.

 Ext.create('Ext.panel.Panel', {
    title: 'Hello',
    width: 200,
    html: '<p>World!</p>',
    listeners: {render: function(c){c.el.on('click', function() { alert('onclick');});}},
    renderTo: Ext.getBody()
});
like image 110
rwilliams Avatar answered Oct 05 '22 22:10

rwilliams