11

Im trying to get the component that is active/focused at a given time. I already know that you can get a HTMLElement with the cross-browser javascript function document.activeElement.

How can I cast this element to a Ext.Component or does ExtJs have a similar function?

A1rPun
  • 16,287
  • 7
  • 57
  • 90

2 Answers2

14

Thanks to @sra for this solution:

let activeComponent = Ext.get(Ext.Element.getActiveElement());
A1rPun
  • 16,287
  • 7
  • 57
  • 90
  • Note IE may sometimes throw a Unspecified Error so you should wrap it into a try/catch block. And if it stays undefined use the `document.body` – sra Jan 14 '13 at 15:43
  • 2
    Also note that there is a static helper method that wraps this for you http://docs.sencha.com/ext-js/4-1/#!/api/Ext.dom.Element-method-getActiveElement – sra Jan 14 '13 at 15:44
  • Thank you for your replies, how do you use `getActiveElement()`? – A1rPun Jan 14 '13 at 15:51
  • 1
    Use it like a static method `Ext.Element.getActiveElement()` – sra Jan 15 '13 at 09:45
  • Do you know how to allow components or containers to get focused? – StarQuake Mar 14 '14 at 14:26
  • You should ask a new question with your specific problem :) There is more likely to get an answer instead of asking it in the comments. – A1rPun Mar 17 '14 at 08:03
0

Take a look at this : Ext.FocusManager. I have never used this feature, could you tell me if it fits with your needs?

  • I know this focusmanager and it doesnt have what I was looking for. I use focusmanager to debug some visual aspects of my application. – A1rPun Jan 14 '13 at 15:48