The helper object returned by useField contains a setTouched(isTouched) method. That method accepts only the intended isTouched boolean value, and does not allow skipping validation while setting it.
Desired Behavior
There is a shouldValidate parameter on form-wide setFieldTouched(name, isTouched, shouldValidate) method that allows skipping validation when updating this flag. Would be great to have the equivalent shouldValidate parameter on the field-specific helper setTouched method.
🚀 Feature request
Current Behavior
The helper object returned by
useField
contains asetTouched(isTouched)
method. That method accepts only the intendedisTouched
boolean value, and does not allow skipping validation while setting it.Desired Behavior
There is a
shouldValidate
parameter on form-widesetFieldTouched(name, isTouched, shouldValidate)
method that allows skipping validation when updating this flag. Would be great to have the equivalentshouldValidate
parameter on the field-specific helpersetTouched
method.Suggested Solution
Seems like this would be a straightforward pass-through to add in the helper function here: https://github.com/jaredpalmer/formik/blob/d71efdec147e94b66eba86ec17c715d0d4ef3d29/packages/formik/src/Formik.tsx#L893
I.e. could add the
shouldValidate
parameter to the arrow function and then passing it to thesetFieldTouched
method call.Who does this impact? Who is this for?
This would be handy for folks who are coding complex form inputs and are converting to use the
useField
hook.Describe alternatives you've considered
For now, the workaround is to get
form
object viauseFormikContext
and use thesetFieldTouched
method on that.Additional context
No extra notes to add.
Thanks for all the amazing work on Formik!