简体   繁体   English

React-admin 在创建视图提交后保留表单数据

[英]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

destroyOnUnmount documentation . destroyOnUnmount文档

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.

相关问题 如何在 react-admin 中创建提交按钮,根据表单数据和验证改变外观和行为 - How to create a submit button in react-admin which changes appearance and behaviour depending on form data and validation 在react-admin中创建自定义表单 - Create custom form in react-admin 在React-Admin中点击提交后如何重定向/折叠扩展的编辑表单 - How to redirect/collapse an expanded edit form after hitting submit in React-Admin React-admin:如何在 react-admin v3.2.* 中创建用户配置文件表单? - React-admin: How to create user profile form in react-admin v3.2.*? 如何使用 react-admin 的先前数据预填充创建表单上的某些字段? - How to prefill certain fields on a create form using previous data with react-admin? 在react-admin / react中使用来自API的响应数据初始化表单 - Initializing a form with response data from an API in react-admin/react 如何使用 ArrayInput 在 react-admin 列表视图中填充数据 - How to use ArrayInput to populate data in react-admin list view 如何在 react-admin 中访问自定义组件中的表单数据? - How to access form data in custom components in react-admin? 组件在react-admin的UseQuery中渲染后的数据刷新 - Data Refresh After component render in UseQuery of react-admin 在 React-admin 列表视图中使用输入 - Using Inputs in React-admin list view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM