You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/AccordionForm.md
+31-3Lines changed: 31 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -830,11 +830,39 @@ const PersonEdit = () => (
830
830
```
831
831
{% endraw %}
832
832
833
-
Note that you **must** set the `<AccordionForm resetOptions>`prop to `{ keepDirtyValues: true }`. If you forget that prop, any change entered by the end user after the autosave but before its acknowledgement by the server will be lost.
833
+
Check [the `<AutoSave>`component](./AutoSave.md) documentation for more details.
834
834
835
-
If you're using it in an `<Edit>`page, you must also use a `pessimistic` or `optimistic`[`mutationMode`](./Edit.md#mutationmode) - `<AutoSave>` doesn't work with the default `mutationMode="undoable"`.
835
+
An alternative to the `<AutoSave>`component is to use [the `<AutoPersistInStore>` component](./AutoPersistInStore.md). This component saves the form values in the local storage of the browser. This way, if the user navigates away without saving, the form values are reapplied when the user comes back to the page. This is useful for long forms where users may spend a lot of time.
836
836
837
-
Check [the `<AutoSave>` component](./AutoSave.md) documentation for more details.
837
+
To enable this behavior, add the `<AutoPersistInStore>` component inside the form component:
Copy file name to clipboardExpand all lines: docs/AutoPersistInStore.md
+22-7Lines changed: 22 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,17 @@ title: "The AutoPersistInStore Component"
5
5
6
6
# `<AutoPersistInStore>`
7
7
8
-
This [Enterprise Edition](https://react-admin-ee.marmelab.com)<imgclass="icon"src="./img/premium.svg"alt="React Admin Enterprise Edition icon" /> component saves a form data in the store on unmount (e.g. when users leave the page) and reapplies it on mount.
9
-
It's ideal to ensure users don't loose their already filled data in an edit or a create form when they navigate to another page.
8
+
This [Enterprise Edition](https://react-admin-ee.marmelab.com)<imgclass="icon"src="./img/premium.svg"alt="React Admin Enterprise Edition icon" /> prevents data loss in forms by automatically saving the form data in the store when users navigate away from the page. When users return to the page, it reapplies the saved data to the form.
The temporary form data is only saved when the user navigates away from the page, and it is removed when the user submits the form or closes the tab. Users can opt out of the prefilling by clicking the "Cancel" button in the notification.
16
+
17
+
Saved data is not sent to the server. It is only persisted using the [store](./Store.md) and is removed when the user logs out.
18
+
16
19
## Usage
17
20
18
21
Add `<AutoPersistInStore>` inside a react-admin form (`<SimpleForm>`, `<TabbedForm>`, `<LongForm>`, etc.):
@@ -32,17 +35,26 @@ const PostEdit = () => (
32
35
);
33
36
```
34
37
38
+
The component will automatically save the form data in the store on unmount and reapply it when the form is mounted again.
|`getStoreKey`| - |`function`| - | Function to use your own store key. |
40
-
|`notificationMessage`| - |`string`|`"ra-form-layout.``auto_persist_ in_store``.applied_changes"`| Notification message to inform users that their previously saved changes have been applied. |
47
+
|`notificationMessage`| - |`string`|"Applied previous unsaved changes"| Notification message to inform users that their previously saved changes have been applied. |
41
48
42
49
## `getStoreKey`
43
50
44
-
To save the current form data in the [store](./useStoreContext.md), `<AutoPersistInStore>` uses a default key that can be overridden with the `getStoreKey` prop.
45
-
It accepts a function with two parameters:
51
+
To save the current form data in the [store](./useStoreContext.md), `<AutoPersistInStore>` uses the following store key:
52
+
53
+
`ra-persist-[RESOURCE_NAME]-[RECORD_ID]`
54
+
55
+
For example, if you are editing a `posts` resource with the ID `123`, the store key will be: `ra-persist-posts-123`. In case of a create form, the record ID is replaced by `"create"`
56
+
57
+
You can override this key by passing a custom function as the `getStoreKey` prop. It expects two parameters:
46
58
47
59
-`resource`: The current resource.
48
60
-`record`: The current record if you are in an [edit context](./useEditContext.md).
@@ -56,11 +68,14 @@ It accepts a function with two parameters:
56
68
/>
57
69
```
58
70
59
-
The default key is `ra-persist-YOUR_RESOURCE-RECORD_ID` (in case of a create form, the record `id` is replaced by `"create"`), e.g. `ra-persist-customers-5`.
60
71
61
72
## `notificationMessage`
62
73
63
-
When `<AutoPersistInStore>` component applies the changes from the store to a form, react-admin's inform users with a notification. You can customize it with the `notificationMessage` prop:
74
+
When `<AutoPersistInStore>` component applies the changes from the store to a form, react-admin informs users with a notification.
75
+
76
+
The default notification message is `ra-form-layout.auto_persist_in_store.applied_changes`, which is translated using the i18n provider (the default English translation is `Applied previous unsaved changes`).
77
+
78
+
You can customize it with the `notificationMessage` prop:
Copy file name to clipboardExpand all lines: docs/Form.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,6 +292,34 @@ If you're using it in an `<Edit>` page, you must also use a `pessimistic` or `op
292
292
293
293
Check [the `<AutoSave>` component](./AutoSave.md) documentation for more details.
294
294
295
+
An alternative to the `<AutoSave>` component is to use [the `<AutoPersistInStore>` component](./AutoPersistInStore.md). This component saves the form values in the local storage of the browser. This way, if the user navigates away without saving, the form values are reapplied when the user comes back to the page. This is useful for long forms where users may spend a lot of time.
Copy file name to clipboardExpand all lines: docs/Forms.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -621,11 +621,33 @@ const PersonEdit = () => (
621
621
```
622
622
{% endraw %}
623
623
624
-
Note that you **must** set the `<SimpleForm resetOptions>`prop to `{ keepDirtyValues:true }`. If you forget that prop, any change entered by the end user after the autosave but before its acknowledgment by the server will be lost.
624
+
Check [the `<AutoSave>`component](./AutoSave.md) documentation for more details.
625
625
626
-
If you're using it in an `<Edit>`page, you must also use a `pessimistic` or `optimistic` [`mutationMode`](https://marmelab.com/react-admin/Edit.html#mutationmode) - `<AutoSave>` doesn't work with the default `mutationMode="undoable"`.
626
+
An alternative to the `<AutoSave>`component is to use [the `<AutoPersistInStore>` component](./AutoPersistInStore.md). This component saves the form values in the local storage of the browser. This way, if the user navigates away without saving, the form values are reapplied when the user comes back to the page. This is useful for long forms where users may spend a lot of time.
627
627
628
-
Check [the `<AutoSave>` component](./AutoSave.md) documentation for more details.
Copy file name to clipboardExpand all lines: docs/LongForm.md
+31-3Lines changed: 31 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -705,11 +705,39 @@ const PersonEdit = () => (
705
705
```
706
706
{% endraw %}
707
707
708
-
Note that you **must** set the `<LongForm resetOptions>`prop to `{ keepDirtyValues: true }`. If you forget that prop, any change entered by the end user after the autosave but before its acknowledgement by the server will be lost.
708
+
Check [the `<AutoSave>`component](./AutoSave.md) documentation for more details.
709
709
710
-
If you're using it in an `<Edit>`page, you must also use a `pessimistic` or `optimistic`[`mutationMode`](./Edit.md#mutationmode) - `<AutoSave>` doesn't work with the default `mutationMode="undoable"`.
710
+
An alternative to the `<AutoSave>`component is to use [the `<AutoPersistInStore>` component](./AutoPersistInStore.md). This component saves the form values in the local storage of the browser. This way, if the user navigates away without saving, the form values are reapplied when the user comes back to the page. This is useful for long forms where users may spend a lot of time.
711
711
712
-
Check [the `<AutoSave>` component](./AutoSave.md) documentation for more details.
712
+
To enable this behavior, add the `<AutoPersistInStore>` component inside the form component:
Copy file name to clipboardExpand all lines: docs/SimpleForm.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -618,11 +618,33 @@ const PersonEdit = () => (
618
618
```
619
619
{% endraw %}
620
620
621
-
Note that you **must** set the `<SimpleForm resetOptions>`prop to `{ keepDirtyValues: true }`. If you forget that prop, any change entered by the end user after the autosave but before its acknowledgement by the server will be lost.
621
+
Check [the `<AutoSave>`component](./AutoSave.md) documentation for more details.
622
622
623
-
If you're using it in an `<Edit>`page, you must also use a `pessimistic` or `optimistic`[`mutationMode`](https://marmelab.com/react-admin/Edit.html#mutationmode) - `<AutoSave>` doesn't work with the default `mutationMode="undoable"`.
623
+
An alternative to the `<AutoSave>`component is to use [the `<AutoPersistInStore>` component](./AutoPersistInStore.md). This component saves the form values in the local storage of the browser. This way, if the user navigates away without saving, the form values are reapplied when the user comes back to the page. This is useful for long forms where users may spend a lot of time.
624
624
625
-
Check [the `<AutoSave>` component](./AutoSave.md) documentation for more details.
Copy file name to clipboardExpand all lines: docs/TabbedForm.md
+35-3Lines changed: 35 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -788,12 +788,44 @@ const PostEdit = () => (
788
788
```
789
789
{% endraw %}
790
790
791
-
Note that you **must** set the `<TabbedForm resetOptions>`prop to `{ keepDirtyValues: true }`. If you forget that prop, any change entered by the end user after the autosave but before its acknowledgement by the server will be lost.
791
+
Check [the `<AutoSave>`component](./AutoSave.md) documentation for more details.
792
792
793
-
If you're using it in an `<Edit>`page, you must also use a `pessimistic` or `optimistic`[`mutationMode`](https://marmelab.com/react-admin/Edit.html#mutationmode) - `<AutoSave>` doesn't work with the default `mutationMode="undoable"`.
793
+
An alternative to the `<AutoSave>`component is to use [the `<AutoPersistInStore>` component](./AutoPersistInStore.md). This component saves the form values in the local storage of the browser. This way, if the user navigates away without saving, the form values are reapplied when the user comes back to the page. This is useful for long forms where users may spend a lot of time.
794
794
795
-
Check [the `<AutoSave>` component](./AutoSave.md) documentation for more details.
0 commit comments