Skip to content

Commit 1a9f02b

Browse files
committed
test using custom save with submitError
1 parent 21e88e6 commit 1a9f02b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

examples/simple/src/comments/CommentEdit.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Title,
1515
minLength,
1616
} from 'react-admin'; // eslint-disable-line import/no-unresolved
17+
import { useDataProvider } from 'ra-core';
1718

1819
const LinkToRelatedPost = ({ record }) => (
1920
<Link to={`/posts/${record.post_id}`}>
@@ -50,7 +51,18 @@ const CommentEdit = props => {
5051
save,
5152
basePath,
5253
version,
53-
} = useEditController(props);
54+
} = useEditController({ ...props, undoable: false });
55+
56+
const dataProvider = useDataProvider();
57+
58+
async function mySave(values) {
59+
const results = await dataProvider.update(resource, values);
60+
if (values.body.startsWith('invalid')) {
61+
return {
62+
body: 'dont like it',
63+
};
64+
}
65+
}
5466
return (
5567
<div className="edit-page">
5668
<Title defaultTitle={`Comment #${record ? record.id : ''}`} />
@@ -70,7 +82,7 @@ const CommentEdit = props => {
7082
redirect={redirect}
7183
resource={resource}
7284
record={record}
73-
save={save}
85+
save={mySave}
7486
version={version}
7587
>
7688
<TextInput disabled source="id" fullWidth />

packages/ra-core/src/form/FormWithRedirect.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ const FormWithRedirect: FC<FormWithRedirectOwnProps & FormProps> = ({
9898
: redirect.current;
9999
const finalValues = sanitizeEmptyValues(finalInitialValues, values);
100100

101-
onSave.current(finalValues, finalRedirect);
101+
const result = onSave.current(finalValues, finalRedirect);
102+
return result;
102103
};
103104

104105
return (

0 commit comments

Comments
 (0)