user1255102
user1255102

Reputation: 486

Access textarea value in Controller

I have created a Custom Control that is rendering a textarea (among others).

If a button is clicked, I want to access the current value of the textbox but don't know how to do so. "this.byId("cb-input")" called in the Controller only returns undefined.

CustomControl

....
renderer: function ( oRM, oControl ){
 ...
 oRM.write('<textarea id="cb-input"');
 oRM.addClass("cb-input");
 oRM.writeClasses();
 oRM.write(">");
 oRM.write("</textarea>");
 ...
}

Controler

onInit: function( ){
 ...
 var oPage = this.getView().byId("cb");
 var oCustom = new CustomControl({
    messages: "{/data}"
 });
 oPage.addContent(oChat)
}

Upvotes: 0

Views: 359

Answers (2)

Shanir
Shanir

Reputation: 87

Agree with fareslt -.byId() method return controls that have those Id's assigned directly during instantiation. So if event and it's method is defined correctly, then using fareslt example this.byId("myControlId").getValue() //or getter you have defined should return the value.

Other option is define the button in the aggregation of custom control and binding the press event to the main Control method which fires the event - and therefore from button click you can directly access textarea value.

Moreover, there is standard TextArea control available in OpenUI5 SDK, as you haven't explained why you need custom Control - maybe using standard is also a viable option for you?!

Best, Shanir

Upvotes: 2

fareslt
fareslt

Reputation: 198

Try to remove the id we set during the creation of the custom control and set and id to the custom control during instantiation, than you can get your custom control byId and get the value.

      onInit: function( ){
 ...
 var oPage = this.getView().byId("cb");
 var oCustom = new CustomControl({
    id : "myControlId"
    messages: "{/data}"
 });
 oPage.addContent(oCustom)
}

Upvotes: 1

Related Questions