RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.17k forks source link

Wrong value when used for BRL currency #2343

Open eliasfank opened 4 years ago

eliasfank commented 4 years ago

I'm trying to use the Inputmask for a BRL money field. It is working correctly when the user types the value on the field, but when the field has an initial value or when a value need to be set on the field, it goes wrong.

Maybe I'm forgetting something or there is another way to achieve the following behavior: Masking: 3212.55 => R$ 3.212,55 Unmasking: R$ 3.212,55 => 3212.55

I really appreciate any help on my solution or to find the bug in the src.

ferk6a commented 4 years ago

The problem is that it's unmasking and masking with , as the decimal separator. I also don't like this behavior, but I fixed it in my application by doing some replaces. Because this works correctly:

Masking: 3212,55 => R$ 3.212,55 Unmasking: R$ 3.212,55 => 3212,55

diegomagikal commented 4 years ago

There seems to be a bug with the original onBeforeMask function. So, you can do it works simply overriding this function. Check my fiddle: https://jsfiddle.net/diegomagikal/rcgton14/1/