0
votes

XML View

<TextArea id="message"
  maxLength="100"
  width="100%"
  valueLiveUpdate="true"
  showExceededText="false"
  placeholder="Type here.."
  required="true"
/>

Controller

onInit: function() {
  // ...
  this.getView().byId("message").setText("");
},

Here I tried two commands to clear the text area values. But got error

  • this.getView().byId("message").setText("");

    TypeError: this.getView(...).byId(...).setText is not a function

  • sap.ui.getCore().byId("message").setText("");

    TypeError: sap.ui.getCore(...).byId(...) is undefined.

How to clear TextArea values from JS?

1
In case there is no clarity which byId-API to use, take a look at "Difference Between this.getView().byId(), this.byId(), and sap.ui.getCore().byId() "Boghyon Hoffmann

1 Answers

6
votes

The control sap.m.TextArea doesn't have the text property and thus no such mutator and accessor either. Instead, the text value can be set via the property value since the control extends InputBase.

Therefore, the line should be:

this.byId("message").setValue();