【问题标题】:How to handle two different onSubmit functions in react-forms?如何在 react-forms 中处理两个不同的 onSubmit 函数?
【发布时间】:2019-11-26 13:02:59
【问题描述】:

我有一个祖父容器,其中有子组件,其中还有另外两个子组件。

这两个子组件是 redux 表单。

现在我想通过表单验证处理这两个表单提交事件并执行不同的任务。如何使用 redux-forms 实现?

我尝试使用自定义道具,但 激活 表单验证

这是我的代码:

父容器:

const props = {
 onSubmit: this.confirmChangeBillingInformation,
}
return <CompanyDetails {...props} />;

子组件:

const CompanyDetails = (props) => {
 <ChangePaymentInformation {...props} />

 <ChangeCompanyPricing {...props} />
}

grand child forms:有两种这样的形式

const ChangeCompanyPricing = ({ classes, companyPricing, showChangePricingModal, actions, handleSubmit }) => {
 return (
 ...
 <form onSubmit={handleSubmit}>
  <Button color="primary" type="submit" variant="raised">
    Save
  </Button>
 ...
 )
}

【问题讨论】:

  • 你为什么不能试试子裁判?
  • @hrudaykumarreddy 我很陌生。你能帮忙吗?

标签: javascript reactjs react-redux redux-form


【解决方案1】:

在父容器中将变量的名称更改为handleSubmit,因为在子组件中,您在ChangeCompanyPricing 组件中获得handleSubmit 道具。它根本没有定义。所以更改它。在confirmChangeBillingInformation 中进行验证。我假设所有数据验证所需的将可用于父组件

const props = {
 handleSubmit: this.confirmChangeBillingInformation,
}
return <CompanyDetails {...props} />;

【讨论】:

  • 我正在使用 redux-forms。我指定的代码工作正常,我只想隔离两个不同的 onSubmit 调用。
猜你喜欢
  • 1970-01-01
  • 2012-03-21
  • 2018-11-16
  • 1970-01-01
  • 2016-04-13
  • 1970-01-01
  • 2018-11-16
  • 2023-03-22
  • 2022-01-16
相关资源
最近更新 更多