Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
unframework opened this issue Jan 16, 2020 · 1 comment
Open

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

unframework opened this issue Jan 16, 2020 · 1 comment
Labels

Comments

@unframework
Copy link

unframework commented Jan 16, 2020

馃殌 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:

setTouched: (value: boolean) => setFieldTouched(name, value),

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
Copy link

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

@stale stale bot added the stale label May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants