79097170

Date: 2024-10-17 08:28:32
Score: 1.5
Natty:
Report link

@Boghyon Hoffman's approach is right, but it did not work for me. The delegate was not called on 1.126 (did not test it on another version).

I had to use it this way, by assigning the function to as a property in the object.

I have moved it to a base controller, that way it can be used in multiple controllers, with a oneliner:

BaseController:

setInitialFocus: function(sControlId) {
        var oView = this.getView();
        var oControl = oView.byId(sControlId);
        var fnAfterShow = function() {
            if (oControl && !oControl.isDestroyed()) {
                oControl.focus();
            }
        };
        oView.addEventDelegate({
            onAfterShow: fnAfterShow
        });
    }

Another controller:

onInit() {
    this.setInitialFocus("someControl");
}

Do not forget to disable the autofocus on the App control level.

Reasons:
  • Blacklisted phrase (1): did not work
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Boghyon
  • Low reputation (0.5):
Posted by: nintendojet