React-admin 在创建视图提交后保留表单数据 [英] React-admin keep form data after create view submit

查看:50
本文介绍了React-admin 在创建视图提交后保留表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 react-admin Create 表单中,有没有办法在用户点击保存后保留表单数据?

In a react-admin Create form, is there a way to keep the form data after the user clicks Save?

我想重复使用他们输入的相同表单数据来创建另一条记录.

I want to re-use the same form data that they entered to create the another record.

推荐答案

更新:

根据这个PR,看起来像 react-admin 在创建/编辑表单提交后清除表单状态.

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.

从 PR 中,我了解到传递 redirect={false}to={{ state: { skipFormReset: true } }} 可能会阻止表单状态清除.类似的东西:

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 } }} />

另一个选项(一种解决方法) - 创建后,您可以尝试使用您已经填写(创建)的数据更新当前创建表单 defaultValue.

Another option (a workaround) - after creation, you can try to update the current create form defaultValue with the data you already filled (created).

原答案:redux-form 将在卸载组件时自动销毁您的表单及其状态(数据).

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

destroyOnUnmount 文档.

这篇关于React-admin 在创建视图提交后保留表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆