react-hook-form: [REQ] Ability to return form and field level errors from submission
Is your feature request related to a problem? Please describe. This is a feature request for being able to pass the form errors from a submission.
Describe the solution you’d like
I would like to see the callback passed to handleSubmit be able to handle being returned an object of errors that could be merged into the existing errors object. Including a special case for an overall form-level error.
Describe alternatives you’ve considered I tried manually implementing something like this and it requires a lot of work from the implementer’s side.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 40 (36 by maintainers)
Commits related to this issue
- #211 merge errors into return data from handleSubmit — committed to react-hook-form/react-hook-form by bluebill1049 5 years ago
- #211 merge errors into return data from handleSubmit (#213) — committed to react-hook-form/react-hook-form by bluebill1049 5 years ago
- Revert "#211 merge errors into return data from handleSubmit (#213)" This reverts commit 97511ff3a90ee8a651fe9c5beafda5240fb3662a. — committed to react-hook-form/react-hook-form by bluebill1049 5 years ago
- Revert "#211 merge errors into return data from handleSubmit (#213)" (#217) This reverts commit 97511ff3a90ee8a651fe9c5beafda5240fb3662a. — committed to react-hook-form/react-hook-form by bluebill1049 5 years ago
This is a great library, but a little criticism, the more Wishlist is implemented, the more difficult it is to maintain and develop the library, I paid attention to the number of bug fixes for the whole time. Also, in my case, errors are returned in a different format, it depends on the server, and it is easier for me to call SetError than to convert to a different format, in general, a very narrow case.
I like that the library is really small and has a unique approach to form control, I would not want it to become a Swiss knife. Maybe it’s better to have a Cookbook?
@bluebill1049 You can revert that code for now and we can continue the discussion.
Hmm, I suppose I could build this out as a helper in my apps.
Just seems like it would be easier to have in the lib and a nice DX win.
@JeromeDeLeon What other setters are you passing? Would it be easier to remove the wrapping function and just return an error object?
and having just re-looked at this code, I’ve realised that typing the
setFormErrorsfunction above is futile, because TypeScript doesn’t provide runtime type safety. Also where the types are provided by the library, just pull them in… doh! 🤦🏻♂️Update to snippet from above:
@stramel maybe we just stick with
setErrorfor now?oh you are right about that! going to fix that! thanks
Hmm I’m not sure it will be as obvious to some developers that they will need to return
Maybe we could just set the type differently manually?
setError(name, error, 'submissionError').You could potentially do a check like:
@bluebill1049 WDYT about using this to ensure the same error object? instead of just spreading the errors?
@stramel,
setStatusinconst [status, setStatus] = useState({ });for other things I want to do in my form like successfully detecting if It successfully submitted or not.what’s your thoughts on this @barrymay ? I personally don’t mind it, it makes server validation simpler, you don’t have to manually call
setError.I don’t think so. I don’t have any use case for it that want me to use the return errors feature cuz like I said, I came from
formikthat didn’t have that. Maybe for others 👍In my use case,
just sharing 😉
Shoot forgot to mention that I didn’t test how this worked with nested naming
That’s what I was thinking. If we want, it could be limited to registered fields.
sure i can take a look at that