I am using formik as a library to handle form data.
For some fields, I would like to use a different underlying type, e.g. I use decimal.js-light for handling of decimal values*.
So in my form values, I'd like my decimal types to be represented by this type. However, when the user is typing, it should still treat the input as string rather than a number. A classic example is if the user wants to change "1000" to "2000", if they delete the "1" and enter a "2", the value would become "20", if the input is treated as a number during typing.
We also need to handle the user's locale (the locale depends on the country of the tenant that the user is a member of, not the browser settings).
So when the form is loaded, I need to convert the decimal to a localized string. When I submit the form, I need parse the string in the user's locale, which is not trivial.
There are also some dependent fields, e.g. I have a quantity and amount field - and we calculate the a total as quantity*amount (using decimal.js). So now I have the rules for localized parsing 3 different places, when submitting, when validating input, and when calculating the total.
Are there patterns for formik for dealing with a different underlying abstraction of the type of data you're working with?
* We use decimal.js because JavaScript doesn't handle decimal precision, e.g. 0.1+0.2 does not equal 0.3. For many scenarios this doesn't matter, but in my application, I need decimal precision.