Skip to content

Commit

Permalink
Improve documentation for the <SaveButton> and the <Toolbar>
Browse files Browse the repository at this point in the history
  • Loading branch information
Luwangel committed Jul 17, 2020
1 parent 13f3bf5 commit 223d110
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ export const PostCreate = (props) => (
);
```
Another use case is to remove the `<DeleteButton>` from the toolbar in an edit view. In that case, create a custom toolbar containing only the `<SaveButton>` as a child;
Another use case is to remove the `<DeleteButton>` from the toolbar in an edit view. In that case, create a custom toolbar containing only the `<SaveButton>` as a child:
```jsx
import * as React from "react";
Expand All @@ -1194,6 +1194,21 @@ 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>`:
```jsx
import * as React from 'react';
import { Edit, SimpleForm, Toolbar } from 'react-admin';

export const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm toolbar={<Toolbar alwaysEnableSaveButton />}>
...
</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 Expand Up @@ -1248,7 +1263,7 @@ You can customize each row in a `<SimpleForm>` or in a `<TabbedForm>` by passing
You can find more about these props in [the Input documentation](./Inputs.md#common-input-props).
You can also [wrap inputs inside containers](#custom-row-container), or [create a custom Form component](#custom-form-component), alternative to `<SimpleForm>` or `<TabbedForm>`.
You can also [wrap inputs inside containers](#custom-row-container), or [create a custom Form component](#custom-form-component), alternative to `<SimpleForm>` or `<TabbedForm>`.
### Variant
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import { sanitizeButtonRestProps } from './Button';
/**
* Submit button for resource forms (Edit and Create).
*
* @typedef {Object} Props the props you can use (other props are injected by Toolbar)
* @typedef {Object} Props the props you can use (other props are injected by the <Toolbar>)
* @prop {string} className
* @prop {string} label Button label. Defaults to 'ra.action.save', translated.
* @prop {boolean} disabled Injected by SimpleForm, which disables the SaveButton
* @prop {boolean} disabled Disable the button.
* @prop {string} variant Material-ui variant for the button. Defaults to 'contained'.
* @prop {ReactElement} icon
* @prop {string|boolean} redirect Override of the default redirect in case of success. Can be 'list', 'show', 'edit' (for create views), or false (to stay on the creation form).
Expand Down

0 comments on commit 223d110

Please sign in to comment.