Skip to content

Commit

Permalink
Merge pull request #5285 from marmelab/fix-documentation
Browse files Browse the repository at this point in the history
Improve the documentation of the SaveButton when customizing the Toolbar
  • Loading branch information
djhi authored Sep 23, 2020
2 parents 1b5d158 + 6cc12d3 commit 7f13933
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ export const PostEdit = (props) => (
);
```

By default the `<SaveButton>` is disabled when the form is `pristine`. You can bypass this behavior and always enable it without recreating the whole `<Toolbar>`:
In the default `<Toolbar>`, the `<SaveButton>` is disabled when the form is `pristine`. You can bypass this behavior and always enable it without customizing the `<Toolbar>` thanks to the prop `alwaysEnableSaveButton`:

```jsx
import * as React from 'react';
Expand All @@ -1241,6 +1241,27 @@ export const PostEdit = (props) => (
);
```

But if you want to customize the `<Toolbar>` (to remove the `<DeleteButton>` for example), you have to manage the _disabled_ behaviour of the `<SaveButton>` by yourself:

```jsx
import * as React from "react";
import { Edit, SimpleForm, SaveButton, Toolbar } from 'react-admin';

const PostEditToolbar = props => (
<Toolbar {...props} >
<SaveButton disabled={!props.pristine} />
</Toolbar>
);

export const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm toolbar={<PostEditToolbar />}>
// ...
</SimpleForm>
</Edit>
);
```

Here are the props received by the `Toolbar` component when passed as the `toolbar` prop of the `SimpleForm` or `TabbedForm` components:

* `handleSubmitWithRedirect`: The function to call in order to submit the form. It accepts a single parameter overriding the form's default redirect.
Expand Down

0 comments on commit 7f13933

Please sign in to comment.