Skip to Content
avatar image
Former Member

Passing value from input to another view..

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"); }

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Feb 19, 2017 at 06:23 AM

    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>

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 19, 2017 at 12:29 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 19, 2017 at 05:32 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

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