views:

64

answers:

2

here is the code and also i want onPaste event instead of click but nothing working

var mpan0 = new Ext.form.TextField({
    name:'mpan[]' ,
    value:0 , 
    allowblank:false , 
    enableKeyEvents:true ,
    fieldLabel:'Mpan',
    maxLength:2,
    width:35
    });

mpan0.addListener('click', function(){ 
    alert( "amiy");
});
A: 

ExtJs uses on, so it should be

mpan0.on("click", function(){
    alert("amiy");
});

But you can also add it declaratively

var mpan0 = new Ext.form.TextField({
    name:'mpan[]' ,
    value:0 , 
    allowblank:false , 
    enableKeyEvents:true ,
    fieldLabel:'Mpan',
    maxLength:2,
    width:35,
    listeners: {
        "click": function() {
            alert("amiy");
        }
    }
});
Sean Kinsey
hi sean, no it is also not working
Extjs Commander
Then there is something else wrong - the above code is correct. Have you tried a debugger? Btw, `on` and `addListener` is the same..
Sean Kinsey
hi i do not know how to use debugger , also i tried ur code i donot know its nor working in any condition , i think we have to find the variable that needs to be set for activating on click ,or there is an answer which works which is given by "owlness" ,May be u can suggest better code , or u get something out of it
Extjs Commander
+3  A: 

Ext.form.TextField does not have a 'click' event. You can see the events it does support at:

http://www.sencha.com/deploy/dev/docs/?class=Ext.form.TextField

The closest I can think of to what you are seeking is the 'focus' event.

If you really must have a click event you can try attaching a listener to the field object's fundamental DOM element:

Ext.form.TextField({
    listeners: {
        afterrender: function( field ) {
            field.getEl().on('click', function( event, el ) {
                 // do something on click
            });
        }
    }
});

I can't claim to know how successful that will be, however.

Documentation on Ext.Element's click event can be found at:

http://www.sencha.com/deploy/dev/docs/?class=Ext.Element

owlness