jquery.inputmask mask with Real Currency values

Asked

Viewed 6,159 times

4

I’m using the plugin jquery.inputmask for various types of mask in the imputs of my application and including for format 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 works very well, for example: R$ 2.500,50.
Already with rounded values, for example: R$ 2.000,00 (when recovering data from BD) the mask is changing the point by the comma and returning a value R$ 2,00.

Someone managed to get around this problem for real coins?

  • More specific Details: https://github.com/RobinHerbots/Inputmask/issues/1418

1 answer

4


It is possible to use the callback method onBeforeMask() to get around the problem of en decimal conversion.

$('.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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.