The callback function for the validate prop of the Formik component receives form values only.
Desired Behavior
Apart from the form values, helpers such as setFieldValue passed onto the callback function would make things a lot easier.
Suggested Solution
In the Formik component, just pass on the helpers while calling the validate prop.
Who does this impact? Who is this for?
This is for people who want to pass on the setFieldValue as context to the yup schema. Some interdependent fields in the schema are async and require communication with an external api. If the schema test function returns true for one of the field, the value of the api call is often the value of the second interdependent field. This will save us from doing multiple api calls.
Describe alternatives you've considered
The alternative that I'm using right now is that in the yup schema, I'm doing just the synchronous validation (ie no calls to the api). In the Field component, I'm using a useEffect hook with the value, error and isValidating properties from the useFormikState hook. If value is true, error is none and isValidating is false, then I make an api call to the external service and based on the results of that api call, I either call setFieldValue or setFieldError. Here's a sample of what I am doing right now.
Feature request
Current Behavior
The callback function for the
validate
prop of theFormik
component receives form values only.Desired Behavior
Apart from the form values, helpers such as
setFieldValue
passed onto the callback function would make things a lot easier.Suggested Solution
In the Formik component, just pass on the helpers while calling the
validate
prop.Who does this impact? Who is this for?
This is for people who want to pass on the
setFieldValue
as context to theyup
schema. Some interdependent fields in the schema are async and require communication with an external api. If the schematest
function returns true for one of the field, the value of the api call is often the value of the second interdependent field. This will save us from doing multiple api calls.Describe alternatives you've considered
The alternative that I'm using right now is that in the
yup
schema, I'm doing just the synchronous validation (ie no calls to the api). In theField
component, I'm using auseEffect
hook with thevalue
,error
andisValidating
properties from theuseFormikState
hook. Ifvalue
is true,error
is none andisValidating
is false, then I make an api call to the external service and based on the results of that api call, I either callsetFieldValue
orsetFieldError
. Here's a sample of what I am doing right now.