How to Focus on Input Field after Navigation

2019-09-15 11:32发布

How to focus on input field after navigating back from a child page?

Child Page

onNavigateBtnClick: function() {
    var oHistory = History.getInstance();
    var sPreviousHash = oHistory.getPreviousHash();
    if (sPreviousHash !== undefined) {
        history.go(-1);
    } else {
        var bReplace = true;
        this.getRouter().navTo("HomePage", {}, bReplace);
    }
},

Parent Page

onAfterRendering: function() {
    jQuery.sap.delayedCall(500, this, function() {
        this.getView().byId("InputField").focus();
    });
},

Problem

  1. When the nav back button is clicked first time, the onAfterRendering hook is called.
  2. If I do some action on child page then click on the nav back button, the onAfterRendering method would not be called.

标签: sapui5
0条回答
登录 后发表回答