cancel
Showing results for 
Search instead for 
Did you mean: 

Capture value from input field in view

Former Member
0 Kudos

Hi there! I'm trying to capture the value of an input field in a Fiori view with no luck at all. I’ve created the input field as follows:

Input id="ZFINALPRICE" class="soc-table-label-elem-align" value="{path: 'soc_cart>CustomFinalPrice', formatter:'sap.ca.ui.model.format.AmountFormat.FormatAmountStandard'}" type="Number" valueLiveUpdate="true" enabled="true" editable="true"/

And I’m trying to capture its value this way:

var oVal = this.getView().byId("ZFINALPRICE");

var oVal = this.getView().byId("ZFINALPRICE").getValue();

Everything seems to be OK despite captured value is “”…empty. What am I doing wrong? Can anybody help me? Capture is attached....

Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

former_member227918
Active Contributor
0 Kudos

Hello,

I am not sure why your code is not working, might be "This" may be referring to some other object it depends from where you're calling the function.

just try this once

on init:

this._oPriceInput = this.byId("ZFINALPRICE"); 


in prepData() : this._oPriceInput.getValue()

But Recommended is:

if your model is having twoway binding mode, then you should use below code:

var oVal = this.getView().getModel("soc_cart").getProperty("/CustomFinalPrice");

Regards,

Akhilesh

Former Member
0 Kudos

Solved!

My problem is that I was trying to retreive a table value (did not mention that!) by using "this.byId("ZFINALPRICE")".


So I finally used using "for" instruction...and it worked.

Thanks to everybody!

🙂

Answers (1)

Answers (1)

SergioG_TX
Active Contributor
0 Kudos

check out

https://sapui5.netweaver.ondemand.com/#docs/guide/91f233476f4d1014b6dd926db0e91070.html

create a 2 way binding JSON model - using MVC and then you should be able to retrieve and set the model.

SAPUI5 SDK - Demo Kit

it is a better approach (best practices as well)