0

What I want to achieve is to set a handler/function to an Enter event, but in my case there's two different functions I want to invoke so my plan is to set the other Enter event to have a ctrl:true config/property. But it doesn't work, the only thing that works is whoever is the last one declared (since this is how compiler reads the code [top to bottom]).

Below is a brief preview of my code:

Ext.define('mynamespace'{
    extend: 'Ext.window.Window',
    alias: 'widget.myalias',
    requires: [  //all my requires here]

    modal: true,
    keyMapEnabled:true,
    keyMap: {
        Enter: {  //this works if I don't have the keyMap after this
             handler: 'myfunction'
        },
        Enter: {  //this is the one that only works since this is the last event that is initialized after the screen/window is rendered/loaded
             handler: 'myhandler',
             ctrlKey: true
        }
    }
});

I tried the ones on https://docs.sencha.com/extjs/6.5.1/modern/Ext.mixin.Keyboard.html#method-getKeyMap, but it didn't worked on my part.

This is the one that worked for me: https://fiddle.sencha.com/#view/editor&fiddle/1tre

JC Borlagdan
  • 3,318
  • 5
  • 28
  • 51

1 Answers1

2

You can't. The best you can do is check the event in the handler and delegate:

handler: 'onEnter',

// Later
onEnter: function(e) {
    if (e.ctrlKey) {
        this.onEnterWithCtrl();
    } else {
        this.onEnterWithoutCtrl();
    }
}
Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66