[英]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
?在 react-admin
Create
表单中,有没有办法在用户单击Save
后将用户输入表单的任何信息保留在屏幕上?
I want to re-use the same form data that they entered to create the another record.我想重新使用他们输入的相同表单数据来创建另一条记录。
Update: 更新:
According to this PR , it looks like react-admin
clears the form state after Create / Edit Forms submission. 根据此PR ,看起来
react-admin
在“创建/编辑表单”提交后清除了表单状态。
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. 从PR,我知道传递
redirect={false}
和to={{ state: { skipFormReset: true } }}
可能会阻止清除表单状态。 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). 另一个选项(一种解决方法)-创建后,您可以尝试使用已经填充(创建)的数据更新当前创建表单
defaultValue
。
Original answer: redux-form
will destroy your form and its state (data) automatically when your component is unmounted. 原始答案:卸载组件时,
redux-form
将自动破坏您的表单及其状态(数据)。
You can prevent this default form behaviour and keep your form's state after unmounting, as passing: 您可以防止这种默认的表单行为,并在卸载后通过以下方式保持表单的状态:
destroyOnUnmount: false
Before updating react-admin to v3.19 redirect={false}
did the job and preserved the inputs.在将 react-admin 更新到 v3.19 之前,
redirect={false}
完成了这项工作并保留了输入。
After update:更新后:
redirect={false}
: remains at current the route and clears the form (does not re-render, and forms are cleared on default) redirect={false}
:保持当前路由并清除表单(不重新渲染,默认清除 forms)
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. redirect={create/edit}
:保持在当前的创建路径,在呈现组件时将条目保留在输入表单中,并且输入值可能取自某些内部 state 处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.