fiorello88
fiorello88

Reputation: 13

Get Current Focused Element

How can I get the element with the currently active focus in a SimpleForm? I have already tried with getFocusInfo(), but I have information if the element I try to select has an active focus

Upvotes: 1

Views: 1909

Answers (1)

Boghyon Hoffmann
Boghyon Hoffmann

Reputation: 18064

You can get the current focused control like this:

UI5 1.119+

// Element required from "sap/ui/core/Element"
Element.getActiveElement();

API Reference: sap.ui.core.Element.getActiveElement

UI5 < 1.119

// Core required from "sap/ui/core/Core"
getCurrentFocusedControl: function() {
  const currentFocusedControlId = Core.getCurrentFocusedControlId(); // deprecated since 1.119
  return Core.byId(currentFocusedControlId); // deprecated since 1.119
},

API Reference: sap.ui.core.Core#getCurrentFocusedControlId

Upvotes: 2

Related Questions