Reputation: 626
With neary each version of SAPUI5 I have strange problems with the sap.ui.model.type.Float
data type in combination with an ODataModel.
See my old post: How to handle number format of OData Edm.Decimal in sapui5 correct?
Later I build a hack to solve the problem (SAPUI5 1.26.x) that worked and looked like mentioned here: https://stackoverflow.com/a/27147305/3783327
This was well working. Now I try to upgrade to 1.28.12 and to the sap.ui.model.odata.v2.ODataModel
model.
I have the following situation:
I bind the control with the usage of the following type:
return new sap.ui.model.type.Float({
maxFractionDigits : 2,
minFractionDigits: 2,
source : {
maxFractionDigits : 2,
minFractionDigits: 2
}
});
According to the documentation the source
is used to define the model format.
If I use it as posted the post will have a comma as seperator instead of a dot.
If I don't use it, the model will receive a float instead of a string (same problem as with 1.26.x).
What is the correct solution to bind a Edm.Decimal
with the Float
datatype so that I can enter the number in the user locale of the browser and it will always be send correct to the server?
Upvotes: 2
Views: 13817
Reputation: 83
I've struggled with the same problem you did and can't find a proper solution by researching. By now, i am using the following method to parse the needed string out of the inputfield, which has a value of type sap.ui.model.type.Float:
new sap.ui.model.odata.type.Decimal().parseValue(input.value, "float");
After that, you can assign this string to the OData Entry you want to create/update.
Not sure if this is a good solution as i am very new to sapui5... Just wanted to share my thoughts on this topic.
Upvotes: 2
Reputation: 626
Meanwhile I detected following documentation: https://openui5beta.hana.ondemand.com/#docs/guide/91f30dbf6f4d1014b6dd926db0e91070.html
If link does not work search for sap.ui.model.type.Float
in https://openui5beta.hana.ondemand.com
I use now the following code:
return new sap.ui.model.type.Float({
maxFractionDigits : 2,
minFractionDigits: 2,
source : {
groupingSeparator: ",",
decimalSeparator: ".",
groupingEnabled: false,
maxFractionDigits : 2,
minFractionDigits: 2
}
});
Looks very complex to just show the Edm.Decimal, not sure if there is a easier solution? I would expect that the client sap.ui.model.odata.v2.ODataModel
is smarter, but maybe not?
Upvotes: 1