nosir / cleave.js

Format input text content when you are typing...
http://nosir.github.io/cleave.js
Apache License 2.0
17.95k stars 1.62k forks source link

RTL numeric input #416

Open ctrl-brk opened 5 years ago

ctrl-brk commented 5 years ago

I need to be able to enter money values starting from cents portion by default. So if a user just types '1' it means 0.01 Another '2' - 0.12 Another '3' - 1.23 Would also be nice to have it right aligned. Is it possible?

architech99 commented 5 years ago

I'm trying to address this as well. It would be a handy scenario for countries that use a comma for the decimal separator. I can already change the decimal separator, but unless someone actually types that character, it's not included in the formatted string. I attempted to update the formatted value in the onValueChanged event handler, but that had it's own issues (because if you add the decimal in, it doesn't allow you to continue past three - in my case - characters because it defaulted to 2 decimals).

Workaround What I ended up doing was adding a blur event which forcibly does some checking to see if the decimal marker is present. If it is, it makes sure we're padded to the right number of decimals (in my case, 2). If the decimal marker is not present, I look at the overall length of the string to decide if I want to append a ".00" to the end or convert the last two digits to decimal places.

While this workaround solves my case, a RTL numeric input at @ctrl-brk describes would be useful for certain scenarios, particularly surrounding currency.