Ivan
Ivan

Reputation: 872

ExtJS 4, keypress event on container

I'm using ExtJS 4.1 MVC and I need to perform some actions after user click Enter button.

I did it this way:

Ext.getDoc().on('keypress', function(event, target) {
    me._enterKeyHandler(event, target, me);
});

But I wonder if somehow I can use Ext.util.KeyMap in Container. In Sencha docs I found something and tried, but it didn't work for me.

var map = new Ext.util.KeyMap({
  // in target I tried: Ext.getCmp('myComponent'), "myComponent", myComponentVar
  target: "my-element",
  key: Ext.EventObject.ENTER,
  fn: function() {alert('enter')}
});

So, how how can I listen to keyPress event bot using 'document' ? Help me, please

Upvotes: 0

Views: 3354

Answers (1)

bhutten
bhutten

Reputation: 526

Ext.util.KeyNav works for me. For example, in a panel:

afterRender: function () {
    this.callParent(arguments);

    this.keyNav = Ext.create('Ext.util.KeyNav', this.el, {
        enter: this.onSubmitButton,
        scope: this
    });
}

This binds the "Enter" key to the onSubmitButton function in the panel.

Upvotes: 1

Related Questions