Most as-I-type-validators-with-invalid-key-blocking do confuse me while I’m typing and editing. Usually they are in my way.
Even worse, many of them deny to accept copy-pasted inputs and mangle it.
Lets say I have some german formatted number with decimals (1.024,99 € => One thousand twentyfour Euro and ninety-nine Cent). Copypasting that from the bill to your input field will probably leave me with one Euro and 2 Cent. A lot of manual editing necessary to get it right again.
Try mine and paste the 1.024,99 without the euro sign (just download the .html and open in in f.e. chrome). It works. Pasting the value without thousands separators also, the thousands separtor will be added to the input value. It does not delete the value of an input with an invalid keystroke, it just does not echo the key. I’m used to a decimal input that works about this way in the gui desktop applications I programmed for 20+ years. In some ways I improved it a bit, in some I let out some handy functionality as it would cost more work. I have never seen a decimal input that works neatly in web applications.
Thanks. I’ll sleep a couple of nights over this one. I have not thought about it thoroughly, this one is copied from the workings of the desktop gui development environment I programmed with for 20+ years. While retrying this environment I see that it replaces the last digit of the integerpart before the decimal separator always when the cursor is put left of it, even if there are more digits in the integerpart. At other cursorpositions (except right left of the decimal separator) in the integerpart the digit is inserted when the max number of digits is not exceeded. A small riddle…
There was recently a library submitted to hacker news: https://nosir.github.io/cleave.js/. There are some interesting comments about not using this https://news.ycombinator.com/item?id=19233637 because it can be very confusing for a user.
I mostly agree with this. I’ve also done format as you type in the past, but given up on it and switched to doing a validation/transformation after the user is done (and also saving the original content so the user can edit easily).
I’m used to desktop applications and find the format as you type at least in the case of a decimal handier than validation/transformation after the user is done. Just try my test html before sending a judgement. It is a lot of work to get it right because there do not seem to be decent libs for this and I have never seen it work in a to me acceptable way on the web. I often found desktop gui’s offering a better ux than web apps.
Thanks again for your mindfullnees. I’m going to change this requirement + the implementation. I think I found out why it works this way in my desktop dev environment. For decimal input you can assign a format property like ‘->,>>>.>>9.99’ (you can find equivalents in other desktop gui dev environments, maybe also in visual form designers for mobile) which is equivalent to numDecimals=2, maxDigits=9, allowNegativeSign in my implementation. The 9 in that format says a digit is always shown, default is 0.00 in case of the shown format (or 0,00 in Europe). For 9 in the format the rule is: replace this number when the cursor is left of it and a digit is typed. Makes sense for the decimal part, and for an integer with format ‘999’ for example, but not in case of a decimal where there are more than one digits in the integer part while the last integer digit is formatted with a 9.
I tried numeral formatting in https://nosir.github.io/cleave.js/. It’s unintuitive and you can even create nonsense values like 1,888. (a number with a decimalseparator at the end). I can understand the rejection when only looking at this input.
Here some research results and conclusions on the value of auto formatting credit card number input while typing: https://baymard.com/blog/credit-card-field-auto-format-spaces as some question this value. I have btw changed and implemented a requirement change in my github project triggered by Peer’s remark. I’m still wondering about factoryd 's remark “you need to decouple from the DOM API” . Maybe a dumb question, but why would you do that?