Numeric field input internationalization

Numeric field input internationalization

CarlomezCarlomez Posts: 2Questions: 1Answers: 0

I'm using DataTables and Editor in solutions which use different languages. I use the internationalization options in DataTable or the render function to format the outputs (decimal numbers, currency, dates) according to the culture selected by the user, but I didn't find a way to tell Editor to use a comma as decimal separator for numeric fields (I'm using inline input, but I don't think this is relevant).

Answers

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    edited March 2015

    Hi,

    Are you using a text input element for the numeric input? The issue there is that the input is freeform text, so really you would need to do any deformatting on the server-side (if you are using the PHP libraries you could consider using setFormatter for example).

    The other option might be to extend the text input type to make it a numeric input, in which case the input options would be governed by the browser's internationalisation rules and the locale settings of the host computer:

    {
      name: "myNumericField",
      attr: {
        "type": "number"
      }
    }
    

    number has reasonably good cross browser support, but not on old browsers.

    Allan

    edit I called it numeric before - the input type is number.

  • CarlomezCarlomez Posts: 2Questions: 1Answers: 0

    Yes, it's number and it works with Chrome and Firefox. Unfortunately it doesn't work with IE (not even IE 11) which has a few known issues with the type 'number' and I need to support IE.
    I would be happy to process the input on the server (or on the client), but I couldn't find a way to do it.
    As far as I understand, Editor takes the numeric value from row/cell Data and convert it to a string using the US format (decimal point) and I could find a way to change that. After editing the input validation (which give a NaN result if I try to use a comma to separate decimals) happens before any of the Editor event (even preSubmit) and I couldn't find a way to replace ',' with '.'

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    Have you read through the formatter documentation? Specifically setFormatter could be used to deformat from a localised number to what the database is expecting.

    Allan

This discussion has been closed.