-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Better handling of form submission errors #4351
Comments
Submission errors are indeed not well covered by react-admin, and require a lot of boilerplate code. It's not just a matter of documentation - we need better APIs on how to customize the behavior in case of submission error. Marking this as enhancement request, feel free to suggest changes. As a side note, here is the relevant section of the react-final-form documentation : https://final-form.org/docs/react-final-form/examples/submission-errors |
This is the issue preventing us from upgrading to ra 3. It seems like there's some fundamental tension in the sense that react-final-form needs errors to come out of Is there a sense of how it might be possible to extend react-admin to support this very common use case? We could potentially contribute some development time to a solution if the RA authors have ideas about how to proceed. |
Hello everyone, I would like to share my thoughts and get info if displaying submission errors is achievable with current react-admin: React Final Form submission errors are stored in Final form Submission Error example expect submission errors to be returned as object literal in
In #4703 @oleg-andreyev propose returning promise in custom |
@bmihelac your |
@drj17 thanks. I wish that sustainable solution for handling submission form errors is added to react-admin. |
Hello everyone, is it possible to do minor changes on the code that was proposed by @bmihelac as long as you don't find better solution. |
Hello 🙂 |
With the addition of server response validation in 3.12, we can now close this issue. |
Is your feature request related to a problem? Please describe.
The documentation is missing a section on how to display validation errors for fields that are coming from API 400 responses. Example response:
Describe the solution you'd like
Clear documentation with straightforward way of displaying validation errors from API.
Describe alternatives you've considered
I have found several issue and answers for this problem when react-admin still used redux-form. I've tried those solutions to no avail just to realize that it is now using react-final-form. Looking through the code I haven't found any easy or straightforward solution.
One solution could be composing the
save
callback provided to the create and edit view by theuseEditController
anduseCreateController
and then saving the error somehow in state and returning it in thevalidate
callback. But this solution is in no way simple and straightforwards.Another solution that I've implemented is using saga to capture the FETCH_ERROR and saving the error in redux. This on the other hand made a big mess on managing state as it had to be removed after displaying it, otherwise it would have affected other forms as well.
Other than that it was hard to figure out how to actually make these errors go away after displaying them, because if they were not removed you couldn't submit the form. For this I had to also save the form state values to figure out which fields changed and which error I didn't have to display anymore.
And to put the cherry on the cake making both frontend and API errors display at the same time was again quite hard. In the end I ended up with a hook of 100 lines, and a lot more lines extract from it to different services.
The text was updated successfully, but these errors were encountered: