cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

binding type with decimal

Former Member
0 Likes
9,311

Hi Guru's,

I am having issues with validating input fields, hopefully someone can explain to me what is going wrong because clearly I am doing something wrong .

I have table in the Hana database which allows to enter materials, some of the fields contain weights and these must be entered in whole or decimal values with a maximum of two decimals. so in my hdbdd file I have an entry like this: "NET_DECL_WEIGHT: numbericDecimal;". This numbericDecimal type is defined as an decimal (type numbericDecimal: Decimal(8,2);).

So enough about the table definition, in my controller file I attached the validation handlers as follows:

      // Attaching validation handlers

      sap.ui.getCore().attachValidationError(function (oEvent) {

        oEvent.getParameter("element").setValueState("Error");

        alert("attachValidationError");

      });

      sap.ui.getCore().attachValidationSuccess(function(oEvent){

        oEvent.getParameter("element").setValueState("None");

        alert("attachValidationSuccess");

      });

      sap.ui.getCore().attachFormatError(function(oEvent){

        oEvent.getParameter("element").setValueState("Error");

        alert("attachFormatError");

      });

      sap.ui.getCore().attachParseError(function(oEvent){

        oEvent.getParameter("element").setValueState("Error");

        alert("attachParseError");       

      });

And in my XML view I created an input field as follows:

        <Input value="{

          path: 'NET_DECL_WEIGHT',

          type:'sap.ui.model.odata.type.Decimal',

          formatOptions: {

            minIntegerDigits: 1,

            minFractionDigits: 2,

            maxFractionDigits: 2,

            decimals: 2,

            decimalSeparator: '.',

            roundingMode: 'HALF_CEILING',

            groupingEnabled: false

          }

        }" textAlign="Right" placeholder="{i18n>assignmentPlaceholderWeight}" description="{i18n>assignmentMaterialWeightDesc}" />

The problem is however that the "attachValidationError" event is raised as soon as I type an decimal value in the input field. A comma is seen as a separator and a dot as a decimal. so when I type "1234,5678" then the "attachValidationSuccess" event is raised and the data is converted into "12345678.00". But when I type "1234.5678" the "attachValidationError" event is raised.

Previously I tried the type "sap.ui.model.type.Float" and that one works fine, however, I couldn't save the data back into the database which is caused (I assume) by the fact that the datafield in Hana is a Decimal and I Could not find a way to define it as a Float value.

I don't know if you need any more information, if so please let me know. I am still quiet new with these binding techniques but love to learn how to do this in a correct way since in the past I wrote seperate "onChange" functions for this which I like to avoid if possible.

Kind Regards,

Nico

View Entire Topic
junwu
SAP Champion
SAP Champion
0 Likes

What's issue? what u want to achieve?

Former Member
0 Likes

Hi Jun Wu,

I want these fields to check that only numeric values are added and when more then 2 decimals are entered it should round the second decimal up or down. I don't know how sapui5 handles locales because the app will be used in different countries of which some use 'comma's' and some use 'dots' as a decimal notation.

But my main issue at the moment is that an error in the validation is raised as soon as I enter a decimal value which I don't understand since the type is an odata Decimal type?

actually, what I noticed is that I can write any number ending on .00 and is gives a 'success' message e.g. 1234.00 validates successfull. But when I increase the decimal e.g. to 1234.01 then it gives an validation error... And I have no idea why?