0

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?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Naveen
  • 757
  • 3
  • 17
  • 41
  • 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()` "](https://stackoverflow.com/a/48640283/5846045) – Boghyon Hoffmann May 05 '18 at 13:25

1 Answers1

6

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();
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170