Dojo: how to find if the widget is concentrated in dojo

advertisements

how do I find out if my custom widget has focus in Dojo?

i have dojo editor i wnat to know if the editor has already focus or not?


you can use the module dijit/focus to find out the focus

FROM DOJO DOCS

Tracking active widgets

At any point in time there is a set of (for lack of a better word) “active” or “focused” widgets, meaning the currently focused widget and that widget’s ancestors. “Ancestor” can mean either DOM ancestor (ex: TextBox –> Form), or a logical parent-child relationship (ex: TooltipDialog –> DropDownButton).

For example, if focus is on a TextBox inside a TabContainer inside a TooltipDialog triggered by a DropDownButton, the stack would be TextBox –> ContentPane –> TabContainer –> TooltipDialog –> DropDownButton.

The activeStack[] parameter indicates this set of widgets, and an app can monitor changes to activeStack[] by:

require([ "dijit/focus" ], function(focusUtil){
 focusUtil.watch("activeStack", function(name, oldValue, newValue){
  console.log("Focused widget + ancestors: ", newValue.join(", "));
});
});