4

Why are my key events not working in the following example? The 'blur' event works, but none of the key events work on my textfield (I also tried 'keydown').

I tried using the 'control' construct on the controller as well, but that doesn't work either.

Ext.define('Plus.view.MyController', {
    extend: 'Ext.app.ViewController',

    alias: 'controller.mycontroller',
    control: {
        '#mytextfield': {
            blur: function() {
                alert("oink")
            },
            keypress: function() {
                alert("moo")
            },
            keyup: function() {
                alert("quack")
            }
        }
    }
});

Ext.define('Plus.view.MainView', {
    extend: 'Ext.container.Container',

    items: [{
        xtype: 'textfield',
        id: 'mytextfield',
        controller: 'mycontroller',
        listeners: {
            blur: function() {
                alert("oink 2")
            },
            keypress : function() {
                alert("moo 2")
            },
            keyup : function() {
                alert("quack 2")
            }
        }
    }]
});

Ext.application({
    name: 'Plus',
    autoCreateViewport: 'MainView',
    launch: function() {

    }
});

My fiddle is here :

https://fiddle.sencha.com/#fiddle/1d5d

Am I missing something obvious?

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225

1 Answers1

9

keypress and keyup These event only fires if enableKeyEvents is set to true. Set this and your code will work. I created a fidller for you where code is working. Fiddle

UDID
  • 2,350
  • 3
  • 16
  • 31
  • so by default, no key events work in extJS? ...Why? ... that seems so strange. – Oliver Watkins Jul 06 '16 at 13:42
  • ya In doc they mentioned for all three key event fires only after setting it true. yup its strange. you can report to sencha. – UDID Jul 06 '16 at 13:46
  • I'm guessing it might be for performance reasons that they switch them off per default. – Oliver Watkins Jul 06 '16 at 14:20
  • 1
    By default you kan only catch specialkey-event, but not all the "others" keys. It's to prevent to much overhead in the event handler I guess. I'm hardly ever using other key events than specialkey – Sven Tore Jul 06 '16 at 18:27