1

I would like to know how to get the content of TextArea, assign the value to a variable, set it to a model, and then set the variable to another TextArea in another view. I have coded some examples and it works, but not on TextArea.

Here is the example code:

// In init of the Component.js
this.setModel(new JSONModel(), "TransportModel"); // JSONModel required from "sap/ui/model/json/JSONModel"
// In *.controller.js
this.getView().getModel("TransportModel").setProperty("/", {
  "Serial": this.byId("mat_serial").getValue() // "mat_serial" == id of the Input box in XML view
});

In the last step, I set the Text from a different View (also XML and Input Box) with the Value of the Model Element.

<Text text="{TransportModel>/Serial}" />

That worked pretty well.

But how to do the same with the TextArea? How can I do it based on this model? The value that I want to use from the first TextArea should also be on a TextArea in another view.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
bunkar
  • 11
  • 4
  • Does this answer your question? [How to access TextArea's text and/or change it?](https://stackoverflow.com/questions/50189699/how-to-access-textareas-text-and-or-change-it) – Boghyon Hoffmann Jun 24 '20 at 12:59

2 Answers2

1

UI5 supports two-way data binding. I.e. if the user changes something in the UI (e.g. user types something in the text area), that change will be reflected automatically in other bindings that listen to the change.

<!-- In view 1 -->
<TextArea value="{TransportModel>/Serial}" />
<!-- In view 2 -->
<Text text="{TransportModel>/Serial}" />

No need to get input values by hand. Simply let the framework synchronize the value.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
  • PS: to learn more about binding, see [Data Binding](https://openui5.hana.ondemand.com/topic/68b9644a253741e8a4b9e4279a35c247) or [Walkthrough](https://openui5.hana.ondemand.com/topic/3da5f4be63264db99f2e5b04c5e853db) from the documentation. – Boghyon Hoffmann Jun 24 '20 at 11:02
-1

How to use a local json model:

  1. Create

      initItemViewModel: function () {
                    return new JSONModel({
                        Serial: ""
                    });
                }
    
        this._oViewModel = this.initItemViewModel();
        this.setModel(this._oViewModel, "TransportModel");
    
    1. Using

      this.getView().getModel("TransportModel").setProperty("/Serial", serial);

      <Text text="{TransportModel>/Serial}" width="auto" maxLines="1"/>
      
Niels
  • 375
  • 5
  • 15