cleave.js icon indicating copy to clipboard operation
cleave.js copied to clipboard

Allow user to type in both "," and "." as decimal mark

Open iguido95 opened this issue 5 years ago • 5 comments

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.

iguido95 avatar Jul 24 '19 13:07 iguido95

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

maciej-laskowski avatar Jul 31 '19 14:07 maciej-laskowski

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.

peldax avatar Feb 01 '20 01:02 peldax

Hey @peldax would you mind sharing, how did you get it to work?

brunotourinho avatar Jan 27 '23 14:01 brunotourinho

Hey @peldax would you mind sharing, how did you get it to work?

I didnt get it to work. 😕

peldax avatar Jan 27 '23 15:01 peldax

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 += ',';
    }
});

toussaintcarlotti avatar Apr 23 '23 16:04 toussaintcarlotti