-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return value for validateField #2021
Comments
@good-idea just wanted to thank you for a really well written bug report with an alternative I used to work around an almost identical issue! |
This feature would be immensely useful.
I'm curious why you think this should return an object rather than just a bare string of the error. It seems like that would be more intuitive, where |
I was a bit surprised that this wasn't the behavior of the function already |
This is something awesome to have actually. For the given scenario, any other solution would be counter-intuitive. Came across a similar situation where I badly need this feature. |
+1 for the feature. This would be extremely helpful when creating custom onBlur functions where I submit or change global state onBlur but need to validate the input first. As it currently stands I have to validate all fields and only then I can change global state or submit that value. Again, this is helpful when I would like to submit data on a field input basis and not have a button click that submits all fields. |
+1 for this feature. |
+1 for this feature. Facing the same situation as @jagwingchoy |
@johnrom Sorry to quote you here as this discussion is not being aware. |
This is something I ran into when trying to validate a "resend confirmation email" button. There were two fields, email and code, and I wanted to validate both of them on form submit, but only validate email when clicking the resend button. Since <button type="button" disabled={isSubmitting} onClick={() => {
setFieldTouched('email', true, true).then(err => {
if (!err.hasOwnProperty("email")) {
handleResend(values);
}
});
}}>Re-send confirmation code</button> |
+1 for this feature. |
+1 for this feature |
2 similar comments
+1 for this feature |
+1 for this feature |
+1 this would be helpful |
+1 for this feature |
+1 this would be very helpful |
this is a good workaround for me. |
+1 for this feature. |
+1 |
Facing this same issue, expected this function to return the actual error(s). |
more than 5 years have passed, still waiting... |
Just found out that |
🚀 Feature request
Current Behavior
Currently, calling
validateField('firstName')
returnsvoid
(orPromise<void>
. CallingvalidateForm()
, on the other hand, returns the object with errors for the entire form.Desired Behavior
validateField
Returning a single key-value pair, i.e.{ firstName: 'First name is required' }
, if invalid, orundefined
if the field is valid.Suggested Solution
Adding a return value to the function call. Since it is returning
Promise<void>
right now, I imagine this would not be a breaking change.Is there any reason in particular that it is set up this way?
Who does this impact? Who is this for?
Users triggering manual validation of fields. My use case is a custom "Wizard", and I want to validate a limited number of fields for each step, without validating fields on further steps. Something like this:
Describe alternatives you've considered
I can use some state to work around this for now, but it's a little hacky. Here's the workaround:
The text was updated successfully, but these errors were encountered: