Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS4 - Ext.dom.Element and fireEvent

I'm testing ExtJS4, but need some help here...

I have this HTML code:

<input type="button" value="Click" id="sendButton">

<input type="text" id="tbox">

And this script code:

Ext.addBehaviors({
    '#sendButton@click': function (){
        alert("Test");
    }
}); 


Ext.get('tbox').on('keydown', function(e){
    if(e.keyCode == Ext.EventObject.ENTER){
        //Ext.select('#sendButton').fireEvent('click');
        //Ext.get('sendButton').fireEvent('click');
        // this is what I need working....
    }
});

I just want to, when you press enter on a textbox, it will act like you clicked the button.

Can anyone help?

like image 434
Jack Avatar asked Sep 08 '12 18:09

Jack


1 Answers

Ext.get('tbox').on('keydown', function(e){
    if(e.keyCode == Ext.EventObject.ENTER){
        Ext.get('sendButton').dom.click();

    }
});

Though i'd suggets wrapping the above code with Ext.onReady(function(){...})

like image 111
Varun Achar Avatar answered Oct 04 '22 09:10

Varun Achar