2

How to get the char codes of the arrow keys in extjs?

I tried the below code which is working good to get the char codes of all the keyboard buttons but not the arrow keys(also Backspace).

Ext.getDoc().on('keypress', function(event, target) {
        console.log(event.getCharCode())
});

Before asking here, I have gone through the documentation which I can't understand.

and also If I press backspace then the page is redirecting to previous page. I am planning to keep my own function in future on backspace. How to override it in extjs?

I am a beginner. So, please provide simple example..

Mr_Green
  • 40,727
  • 45
  • 159
  • 271

2 Answers2

2

To archive this you need to use monitoring like

instance.mon(Ext.getDoc(), Ext.EventManager.getKeyEvent(), instance.callBack, instance)

see JSFiddle (I think you can check for the right key)

sra
  • 23,820
  • 7
  • 55
  • 89
  • ya this is clearly showing that I should use `keydown` instead of `keypress`.. when I replaced, it is working fine.. thanks. – Mr_Green Feb 05 '13 at 11:51
  • To change html of the selected panel, I am using `Ext.getCmp('myIdHere').setHtml(valueHere)`.. this is not working.. what should I go with instead? (tried `update` too) – Mr_Green Feb 05 '13 at 11:58
  • @Mr_Green Well you should really consider to switch to [this](http://jsfiddle.net/S5BSp/) as evan stated. I is already a good portion of what you need and that in a really clean manner. But I must admit that you will still have a good portion to add before it can full fill all your needs... – sra Feb 05 '13 at 12:30
  • @Mr_Green For the HTML you may call `Ext.getCmp('myIdHere').el.setHTML( html )` – sra Feb 05 '13 at 12:37
  • I am getting error -- `Uncaught TypeError: Cannot read property 'el' of undefined ` – Mr_Green Feb 05 '13 at 12:41
  • @Mr_Green Read the error and think about it. I am pretty sure you got what went wrong ;) – sra Feb 05 '13 at 12:44
  • I am not calling the keydown event in `listener` or `afterrender`.. maybe because of that it is showing that error. If so, then How to call key down event in listener? currently, I am calling the same function which I mentioned in the post (replaced with keydown). – Mr_Green Feb 05 '13 at 12:50
  • @sra Looks like you're making the whole Sudoku yourself lol. Mr_Green You should do some of the work yourself. Some stuff you're asking can be found in the docs and examples of ExtJS. – Johan Haest Feb 05 '13 at 13:26
  • please have a look at this link http://jsfiddle.net/v7hZH/8/ (**not working in fiddle**,shows as transparent) . still I can't understand why this is happening even the `id` is present. I am getting the id in `_clickedElement` variable whenever the user clicks on a child panel. – Mr_Green Feb 05 '13 at 13:27
  • Hey I got the solution, I was actually getting the id of the panel's body not the panel itself. So, the error 'undefined' was invoking all the time. :). Please have a look at this link. http://stackoverflow.com/q/14745691/1577396 – Mr_Green Feb 07 '13 at 07:23
1

There is an example of exactly that in the documentation: http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/keynav/keynav.html

Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
  • Thanks for response.. I will have a look at this too. – Mr_Green Feb 05 '13 at 11:52
  • To change html of the selected panel, I am using `Ext.getCmp('myIdHere').setHtml(valueHere)`.. this is not working.. what should I go with instead? (tried `update` too) – Mr_Green Feb 05 '13 at 11:59