If I use 'parse', then the user can not enter the decimal separator.
Because "9." is parsed as 9 and instantly replaces the input text.
Sandbox: https://codesandbox.io/s/xmj92nnpo
Yep. This is a common problem. If you want to allow decimal points, you have to keep the value as a string, and then convert it to a number at submit time. You can still use parse to remove any illegal characters (or type="number" on your <input>), but you can't parse it into a number on every keypress or you will lose your decimal points.
I end up with my own StatefulInput component, with 'editing' flag in the internal state. And I call Field's 'onChange' event handler only on blur.
https://codesandbox.io/s/2zpn29zzjj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With