Search code examples
sapui5

How to access control from the popup fragment by ID


I want my text area to be empty after I press OK button.

I have try this line this.byId("id").setValue("")

onWorkInProgress: function (oEvent) {
  if (!this._oOnWorkInProgressDialog) {
    this._oOnWorkInProgressDialog = sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
    //this.byId("WIP").value = "";
    //this.byId("WIP").setValue();
    this.getView().addDependent(this._oOnWorkInProgressDialog);
  }
  var bindingPath = oEvent.getSource().getBindingContext().getPath();
  this._oOnWorkInProgressDialog.bindElement(bindingPath);
  this._oOnWorkInProgressDialog.open();
},
        
//function when cancel button inside the fragments is triggered
onCancelApproval: function() {
  this._oOnWorkInProgressDialog.close();
},

//function when approval button inside the fragments is triggered
onWIPApproval: function() {
  this._oOnWorkInProgressDialog.close();
  var message = this.getView().getModel("i18n").getResourceBundle().getText("wipSuccess");
  MessageToast.show(message);
},

The text area will be in popup in the fragment. I am expecting the text area to be empty.


Solution

  • You almost have it, I think. Just put the this.byId("WIP").setValue("") line after the if() block. Since you are adding the fragment as a dependent of your view, this.byId("WIP") will find the control with id "WIP" every time you open the WIP fragment and set its value to blank.

    You are likely not achieving it now because A. it is not yet a dependent of your view and B. it is only getting fired on the first go-around.