cancel
Showing results for 
Search instead for 
Did you mean: 

how to fetch and display input field text from one page to another?

Former Member
0 Kudos

I wanted to know how to fetch the data using getText function and to display the data on another page using setText function, I am confused, where to put the syntax of getText() and getText().

BTW, I am using a button to redirect from the first page to second.

I came accross this syntax, but I am not sure, if it is okay or not..

sap.ui.getCore().byId("inp").getText();

sap.ui.getCore().byId("inp").setText();

could anyone guide me through it???

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Sanjo,


First of all is it input control (or) label control? If it is input control, it doesn't have getText()/setText() methods. It has getValue()/setValue().

Fine to achieve your requirement, you can make use of model property.To do this, you should have a global json model defined.

In your first Page -


var oInputValue = "45"                    //Consider you have a input value

sap.ui.getCore().byId("oInput").setValue(oInputValue);             //Value stored in oInput control

sap.ui.getCore().getModel().setProperty("/oInputValue", oInputValue);      //Store the value in model

In your second Page -


var oInputValue = sap.ui.getCore().getModel().getProperty("/oInputValue");               //You will have the value here as 45

sap.ui.getCore().byId("oSecondInput").setValue(oInputValue);                        //second page input value will have the first page input value.

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi, I have made a form, in which it contains many input fields.

Is it necessary to create a model , need I change or add any function in the controller??

And if I am using a button to redirect to another page, so should this code be included in the button itself?

saivellanki
Active Contributor
0 Kudos

Hi Sanjo,

It's better to use a model rather than passing parameters through view, since it will be useful anywhere in the application. Consider you have many views and you wanted to use the same value in third view, then you can just use this model path to bind the values.

Yes on button click, get all the input values and store it in a model array. So the same model can be used to bind the values in second view.


Use setProperty when you're setting any values and getProperty for getting the values.


Regards,

Sai Vellanki.

Former Member
0 Kudos

yes, then it should be better to make use of models, in case we have to use the data multiple times in different views.

Where do we need to define the model??

saivellanki
Active Contributor
0 Kudos

Hi Sanjo,


In component.js of your App, check this sample - Plunker


In above example - I used parameter passing, you can ignore that.


Regards,

Sai Vellanki.

santhu_gowdaz
Active Contributor
0 Kudos

If you are getting the data from back end then create the model in component.js. If you are going to store data in local then create json model in that controller itself.

Answers (1)

Answers (1)

Former Member
0 Kudos

var input = new sap.m.Input("inp",{

                maxLength:20,

                width:"30%",

  })

var button = new sap.m.Button({

                text: "Button",

           

                 press: function()

                  {

                    

                      app.to(page1);

var oFieldValue1 = sap.ui.getCore().byId("inp").getValue();

                  sap.ui.getCore().byId("i4").setValue(oFieldValue1);

}

This works for me!!!