【问题标题】:Redux Form - how to disable sync/async validation with a flagRedux Form - 如何使用标志禁用同步/异步验证
【发布时间】:2019-01-09 10:48:57
【问题描述】:

我正在寻找最无创的方式来禁用 redux 表单的验证以用于开发/调试目的
我有一个类似于教程https://redux-form.com/8.1.0/examples/wizard/ 的向导表单,但我使用的是字段验证器和异步验证器
我仍然希望显示错误,但即使验证失败也可以继续执行下一个向导步骤
我想在 url 中添加一个标志,例如 ?ignore-validation=true (使用反应路由器)

这是我的向导步骤 1 的片段:

export class CustomerStep1 extends React.PureComponent<FormProps> {
    render(): React.Node {
            const {
                handleSubmit,
            } = this.props;

            const submit = handleSubmit(createValidateCardAction);

            return (
                    <form onSubmit={submit}>

                                    <Field
                                        name="card_number"
                                        placeholder="7777 1234 5678 9012"
                                        component={Input}
                                        validate={cardNumber}
                                    />
...

export default reduxForm({
    form: 'customerWizard',
    destroyOnUnmount: false,
    forceUnregisterOnUnmount: true,
})(CustomerStep1);

【问题讨论】:

    标签: reactjs react-redux react-router redux-form react-redux-form


    【解决方案1】:

    我在这里看到了两种可能性:

    1) 将您的向导表单拆分为多个表单并分别验证它们。您可以创建另一个状态来控制要显示的表单。即使它有更多的状态要管理,我还是会选择那个。

    2) 您可以只保留每个字段的异步验证并在那里抛出错误。此外,您必须创建一个状态来管理页面并在异步验证函数中对其进行管理。我创建了第二种方法的示例:https://codesandbox.io/s/o46k8lx7kz

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-08
      • 2017-12-21
      • 2020-10-20
      • 2017-05-02
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      • 2022-08-12
      相关资源
      最近更新 更多