How to retrieve a field value on SAPUI5

27,349

you can get the control by it's id and then access it's value so in your code:

Accessing the Text control in the controller

sap.ui.getCore().byId("lblCurrency").getText() 

Accessing the Input value control in the controller

sap.ui.getCore().byId("inputAmount").getValue()

The code above show how to access to value in the standard way. If you will use binding (binding is when you have a model which updates your view and if it's 2-way binding also your view updates you model) then in order to access to value you need to access access the model and extract it from there

example of binding and how to use it can be found here:

https://help.sap.com/saphelp_uiaddon10/helpdata/en/91/f0f3cd6f4d1014b6dd926db0e91070/content.htm

Update

in order to get the data from the model you need to use the getProperty function under the model so your code should look some

oModel.getProperty("{PATH_TO_WHERE_THE_PROPERTY_IS_LOCATED",{OPTIONAL_CONTEXT}};
Share:
27,349
Mario
Author by

Mario

Updated on August 04, 2020

Comments

  • Mario
    Mario almost 4 years

    I'm starting on OPENUI5/SAPUI5 and I was trying to access the data for the controls i've implemented. For example:

    <Label text="Amount" /> <Input id="inputAmount" value="{Amount}" /> <Text id="lblCurrency" text="USD" >

    1. How to get the programatically values for inputAmount or lblCurrency?
    2. Initially i'm using a mockup-server, how to get access to the odata model programatically? I'm using:

    console.log( this.getView().getModel().getJSON() );

    I can't get the structure, but i had deployed the data on the objects and actually is showed on screen.