How to access TextArea's text and/or change it?

筅森魡賤 提交于 2020-08-11 02:29:26

问题


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:


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();


来源:https://stackoverflow.com/questions/50189699/how-to-access-textareas-text-and-or-change-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!