仅发送编辑中具有表单输入的数据

发布于 2025-01-20 01:59:37 字数 411 浏览 3 评论 0原文

React admin 在提交数据时不尊重表单中实际存在的表单输入。相反,它会发送最初获取的整个记录​​,无论表单中实际包含哪些输入。

我怎样才能发送表单中显示的输入数据?

示例:假设为编辑表单获取了以下记录:

{ first_name: 'jane', last_name: 'doe', age: 21, email: '[email protected]' }

该表单将仅包含名字和姓氏的输入。我希望表单仅将数据提交到以下输入:名字、姓氏

React admin does not respect the form inputs that are actually in the form when submitting data. It will instead send the entire record that was initially fetched, regardless of which inputs are actually in the form.

How can I just send the data that has inputs displayed in the form?

Example: Given the following record fetched for the edit form:

{ first_name: 'jane', last_name: 'doe', age: 21, email: '[email protected]' }

The form will only have inputs for first_name and last_name. I want the form to only submit data to the following inputs: first_name, last_name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾忌 2025-01-27 01:59:37

您可以使用 underscore.js

pick({ first_name: 'jane', last_name: 'doe',age: 21, email: '[电子邮件受保护]' }, 'first_name', 'last_name')

You can use the _pick from underscore.js

pick({ first_name: 'jane', last_name: 'doe', age: 21, email: '[email protected]' }, 'first_name', 'last_name')

能否归途做我良人 2025-01-27 01:59:37

在React Admin SimpleForm上设置以下道具解决了问题。

  destroyOnUnregister={true}
  sanitizeEmptyValues={false}

除了使用React-Final-Form useform之外,这还使我能够通过更改方法动态添加和删除输入:form.Change(InputName,Undefined),从而阻止它们被提交。

Setting the following props on the react admin SimpleForm fixed the problem.

  destroyOnUnregister={true}
  sanitizeEmptyValues={false}

This in addition to using react-final-form useForm allowed me to dynamically add and remove inputs via the change method: form.change(inputName, undefined) and thus prevent them from being submitted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文