Skip to Content
0

Passing value from input to another view..

Feb 19, 2017 at 06:22 AM

67

avatar image

Hi,

I am trying to pass the value in a text box to another view but the getValue function is throwing an error, please refrer to the following code:-

view.xml

http://www.w3.org/1999/xhtml">

controller

onPress : function(oEvt){ var oInput = sap.ui.getCore().byId("id").getValue(); var oLabel = sap.ui.getCore().byId("label"); app.to("idfirst2"); }

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Mohit Chandwani Feb 19, 2017 at 06:23 AM
0

the content of the view is as follows:

<content>

<Input id="id" type="Text" > <

/Input>

<Button text="Submit" press="onPress" ariaDescribedBy="defaultButtonDescription genericButtonDescription">

</Button>

</content>

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Feb 19, 2017 at 12:29 PM
0

using model binding. get the data from model, never get value from ui control....

Share
10 |10000 characters needed characters left characters exceeded
Mohit Chandwani Feb 19, 2017 at 05:32 PM
0

Thanks Jun for your response, but I would still want to know how to get the value from UI control. The id of the input control is "id" and the code i am writing on controller is

sap.ui.getCore().byId("id").getValue();

and the error I am getting is : Cannot read property 'getValue' of undefined

Show 2 Share
10 |10000 characters needed characters left characters exceeded

core can only work with the real id. if you check with browser dev tool, you will find that ui element is not with id "id"

in the view controller, you can use this.byId("id") to get reference to the ui element.

0

Hi,

First get reference of the view and then get the control reference in the view. (you cannot directly access the control reference as at runtime all "id" are prefixed with view id)

Below is the code in controller

var oView = this.getView();
var sControlId = oView.createId("id");  //this creates id with prefix eg: __xmlview1--id
var sValue = sap.ui.getCore().byId(sControlId).getValue();
1