Feature
It would be nice to have access to the values in the YUP scheme in the validationSchema. Possible use cases: need to validate based on the current values in the form. For example, one numeric value must not exceed another numeric value.
You can always use validate function and call validateYupSchema function directly with your desired context. Here is an example using synchronous validation and custom context.
validate: (values: FormValues) => {
const validationSchema = object().shape({
...
});
try {
validateYupSchema<FormValues>(values, validationSchema, true, {myCustomContext: 'bla'});
} catch (err) {
return yupToFormErrors(err);
}
return {};
},
I suggest looking at how Formik itself uses these functions in the source code.
@latviancoder Yes, it can solve my current problem, I would certainly like to have a second FormValues argument in the function validationSchema, but it's also nice
Most helpful comment
You can always use
validatefunction and callvalidateYupSchemafunction directly with your desired context. Here is an example using synchronous validation and custom context.I suggest looking at how Formik itself uses these functions in the source code.