jquery.inputmask mask with values in real currency

4

I'm using the jquery.inputmask plugin for various mask types in the imputs of my application and even for formatting coins .

I'm using the following custom rule:

<script>
    $(function() {
        $("#money").inputmask('decimal', {
            'alias': 'decimal',
            'radixPoint': ','
            'groupSeparator': '.'
            'autoGroup': true,
            'digits': 2,
            'digitsOptional': false,
            'rightAlign': false
            'placeholder': '0'
    });
</script>

With very specific values it works fine, for example: R$ 2.500,50 . With rounded values, for example: R$ 2.000,00 (when retrieving DB data) the mask is exchanging the period with the comma and returning a value R$ 2,00 .

Has anyone managed to work around this problem for currencies in Real?

    
asked by anonymous 13.10.2016 / 20:49

1 answer

2

You can use the onBeforeMask() callback method to work around the decimal pt-br conversion problem.

$('.moedaReal').inputmask('decimal', {
      radixPoint:",",
      groupSeparator: ".",
      autoGroup: true,
      digits: 2,
      digitsOptional: false,
      placeholder: '0',
      rightAlign: false,
      onBeforeMask: function (value, opts) {
        return value;
      }
});

A bug has been registered for correction in the library.

    
21.12.2016 / 14:12