-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for shouldValidate in FieldHelperProps of useField #2223
base: main
Are you sure you want to change the base?
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/jared/formik-docs/2sxfrnvkp |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6010801:
|
@jaredpalmer / @johnrom |
@mrmuhammadali I appreciate your contribution, but pinging is not a good way to prioritize PRs. |
The code looks good to me and can be approved for implementing this specific technique, but I can't help feel this isn't the right place to decide whether to validate or not. I'd prefer we exposed a method that never validated so that someone could decide on their own to However, that's an API decision that I'll defer to someone else. |
Sorry about that, I’m new to open source contribution but I’ll note that down. |
In case of Dropdowns, Radio Buttons, Toggles and Checkboxes, we’ve to take the decision whether to validate the field or not, so that’s another argument to discuss. As in above mentioned cases, we’ve to call setTouched and setValue at the same time, i.e onChange. |
No worries, the contribution is great, I'm just wondering if Jared had purposefully left out the |
I am the original reporter for #2219, thanks for making this PR @mrmuhammadali! I can see how there might be a broader reason to not include shouldValidate flag, but this would be quite useful in some complex field use cases (came up twice for me now in the last couple months). As discussed above, for checkbox groups and toggles the conventional validate-on-blur/validate-on-change flags don't really apply anyway, so this flag feels like a fairly uncontroversial feature. Hope to see a decision on this soon, even though I understand that the team is busy. Thanks folks! |
I have a use case where I've disabled
validateOnChange
but wanted to run the validations using onlysetValue
in case of a Checkbox as it only callsonChange
. So I've added the support forshouldValidate
inFieldHelperProps
, i.e.setValue
andsetTouched
.Fixed Issue #2219 in this PR.
View rendered docs/api/useField.md