final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.38k stars 480 forks source link

Setting submission errors after autosaving #815

Open Haegin opened 4 years ago

Haegin commented 4 years ago

Are you submitting a bug report or a feature request?

I'm not sure if what I'm trying is supported so it could be either.

What is the current behavior?

I've got a form using autosave similar to the example in the docs and I'm trying to set form errors from server side validations in the response.

https://codesandbox.io/s/react-final-form-auto-save-with-debounce-4yn90?file=/index.js is a modified version of the example from the docs that shows roughly what I'm trying to do. The First Name field has a server side validation whereas the Last Name field is validated client side. The client side validation works fine but I can't figure out how to set the server side errors in the form state.

I've tried to use a mutator to allow me to set the errors but setting the errors in the formState doesn't update the field to show the error.

What is the expected behavior?

Using a mutator to set the error object in the form state should update the props passed to Fields so they can render errors.

Sandbox Link

https://codesandbox.io/s/react-final-form-auto-save-with-debounce-4yn90?file=/index.js

What's your environment?

Final Form 4.20 React Final Form 6.5.0

MacOS Version 10.15.3 (19D76) Chrome Version 83.0.4103.106 (Official Build) (64-bit)

Other information

If I can somehow configure handleSubmit to ignore the validations so I can use the standard method of setting errors by resolving the response to the errors object that'd also work, but I can't find any way to skip field validations when submitting.

Haegin commented 4 years ago

I'm still having problems with this - is there really no way to set errors on a form outside of calling handleSubmit?

ericchernuka commented 2 years ago

I'm actually running into this right now and was looking for a way to influence the errors so I could still keep all the form behaviour.