Skip to content

Commit

Permalink
Merge pull request #8378 from marmelab/fix-ss-validation
Browse files Browse the repository at this point in the history
[Doc] Improve server side validation example
  • Loading branch information
WiXSL authored Nov 10, 2022
2 parents 58854c4 + f722b48 commit 4ad05e6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,34 @@ You can use the errors returned by the dataProvider mutation as a source for the
```jsx
import * as React from 'react';
import { useCallback } from 'react';
import { Create, SimpleForm, TextInput, useCreate } from 'react-admin';
import { Create, SimpleForm, TextInput, useCreate, useRedirect, useNotify } from 'react-admin';

export const UserCreate = () => {
const redirect = useRedirect();
const notify = useNotify();

const [create] = useCreate();
const save = useCallback(
async values => {
try {
await create('users', { data: values }, { returnPromise: true });
await create(
'users',
{ data: values },
{ returnPromise: true }
);
notify('ra.notification.created', {
type: 'info',
messageArgs: { smart_count: 1 },
});
redirect('list');
} catch (error) {
if (error.body.errors) {
// The shape of the returned validation errors must match the shape of the form
return error.body.errors;
}
}
},
[create]
[create, notify, redirect]
);

return (
Expand Down

0 comments on commit 4ad05e6

Please sign in to comment.