react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Provide a way to specify a value transformation function applies to the data passed to onSubmit

Open ThiefMaster opened this issue 3 years ago • 0 comments

When asking https://stackoverflow.com/q/70774121/298479 I found another question where a comment (even from @erikras IIRC) suggested storing the "raw" data in the value and converting it only during submission. However, there is no clean way of doing that without keeping fields self-contained. For example, with a date field any "custom" format (e.g. locale-specific) should be handled within the field (the value would always be iso format), and for a number field I may need to deal with strings at first to provide decent validation, but the final data should be a number.

My suggestion is to add something similar to format but for the data to be submitted, e.g. transformValue or formatForSubmit (names aren't amazing but not relevant for now).

That way format and validate would still have access to the raw data, but form-level validators and onSubmit would receive data in the format the field wants to "output".

ThiefMaster avatar Jan 20 '22 13:01 ThiefMaster