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
Asked
Active
Viewed 1,404 times
1

Boghyon Hoffmann
- 17,103
- 12
- 72
- 170

fiorello88
- 13
- 5
1 Answers
1
You can get the current focused control like this:
// Core required from "sap/ui/core/Core"
// Element required from "sap/ui/core/Element"
getCurrentFocusedControl: function() {
const currentFocusedControlId = Core.getCurrentFocusedControlId();
return Element.registry.get(currentFocusedControlId);
},

Boghyon Hoffmann
- 17,103
- 12
- 72
- 170
-
`getCurrentFocusedControlId()` might also return `null` (when currently no element has the focus). – user1364368 Dec 16 '21 at 15:02
-
@user1364368 Yes, I remember that. I see that the current API reference doesn't document it. Feel free to create an issue on GitHub about the missing null return value https://github.com/SAP/openui5/issues/new – Boghyon Hoffmann Dec 16 '21 at 15:13
-
@user1364368 UI5 team is working on fixing documentation gab such as other possible return types: https://github.com/SAP/openui5/commit/ce02eb433b310961224f962adc5de747b2ae288c. But `getCurrentFocusedControlId` is still not fixed yet. – Boghyon Hoffmann Jul 14 '22 at 16:59