jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.98k stars 2.79k forks source link

Add shouldValidate param to useField's helper setTouched method #2219

Open unframework opened 4 years ago

unframework commented 4 years ago

🚀 Feature request

Current Behavior

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.

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 the setFieldTouched 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 via useFormikContext and use the setFieldTouched method on that.

Additional context

No extra notes to add.

Thanks for all the amazing work on Formik!

klimashkin commented 4 years ago

I think the same parameter should be added to helpers.setValues for consistency