'React-admin keep form data after create view submit
In a react-admin Create
form, is there a way to keep whatever info the user typed into the form to stay on the screen after the user clicks Save
?
I want to re-use the same form data that they entered to create the another record.
Solution 1:[1]
Update:
According to this PR, it looks like react-admin
clears the form state after Create / Edit Forms submission.
Unfortunately, I didn't find out a documented way, how to prevent this default behavior.
From the PR, I understand that passing redirect={false}
and to={{ state: { skipFormReset: true } }}
may prevent the form state clearing. Something like that:
<CreateButton redirect={false} to={{ state: { skipFormReset: true } }} />
Another option (a workaround) - after creation, you can try to update the current create form defaultValue
with the data you already filled (created).
Original answer:
redux-form
will destroy your form and its state (data) automatically when your component is unmounted.
You can prevent this default form behaviour and keep your form's state after unmounting, as passing:
destroyOnUnmount: false
Solution 2:[2]
Before updating react-admin to v3.19 redirect={false}
did the job and preserved the inputs.
After update:redirect={false}
: remains at current the route and clears the form (does not re-render, and forms are cleared on default)
redirect={create/edit}
: remains at the current create-route, keeps entries in inputforms as it's component is rendered, and input-values are presumably taken from some internal state handling.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | SherylHohman |