cleave.js
cleave.js copied to clipboard
Allow user to type in both "," and "." as decimal mark
For formatting numerals and setting the decimal mark to ",", I would like the user to be able to use "." too as being recognized as the decimal mark and get converted automatically to ",".
Is this currently possible? Or via another way?
I am currently using this library in Vue, and I am not able to replace this as the user types, as the used Cleave component doesn't allow me to replace the 'other' decimal mark to the 'real' one myself.
This is something I am also really looking forward to. I think an extra option allowing to set an array of alternative decimal separators would be great. I have seen such a mechanism implemented in a lot of banks and other financial institutions.
Also, this seems to be a duplicate of #405 and #404
Found this as a similiar issue ,
In my country the preferred decimal separator is ,
and thousand delimiter .
. I successfully setup cleave.js to format input this way and its been nice straightforward experience.
However, some users are confused (probably because they use different keyboard layout) that pressing .
doesn't produce decimal separator. I would like to configure cleave to accept both .
and ,
as keys registered for inserting decimal separator, while keeping the desired formatting.
Hey @peldax would you mind sharing, how did you get it to work?
Hey @peldax would you mind sharing, how did you get it to work?
I didnt get it to work. 😕
new Cleave('.input-currency', {
numeral: true,
delimiter: ' ',
numeralThousandsGroupStyle: 'thousand',
numeralDecimalScale: 2,
numeralDecimalMark: ',',
});
document.querySelector('.input-currency').addEventListener('keydown', function (e) {
if (e.key === '.') {
e.preventDefault();
e.target.value += ',';
}
});