Skip to content
Advertisement

how can I show customized error messaged from server side validation in React Admin package?

Is there any way to perform server side form validation using https://github.com/marmelab/react-admin package?

Here’s the code for AdminCreate Component. It sends create request to api. Api returns validation error with status code 422 or status code 200 if everything is ok.

JavaScript

So the question is, how can I show errors for each field separately from error object sent from server? Here is the example of error object:

JavaScript

Thank you in advance!

JavaScript

Now i have following code, and it’s showing validation errors. But the problem is, i can’t perform redirection after success. Any thoughts?

Advertisement

Answer

If you’re using SimpleForm, you can use asyncValidate together with asyncBlurFields as suggested in a comment in issue 97. I didn’t use SimpleForm, so this is all I can tell you about that.

I’ve used a simple form. And you can use server-side validation there as well. Here’s how I’ve done it. A complete and working example.

JavaScript

If the code needs further explanation, drop a comment below and I’ll try to elaborate.

I hoped to be able to do the action of the REST-request by dispatching an action with onSuccess and onFailure side effects as described here, but I couldn’t get that to work together with SubmissionError.

Advertisement