如何从redux-form获取字段值

时间:2017-07-18 15:32:10

标签: reactjs redux-form

我无法在提交回调中获取字段值。相反,我在那里收到一个活动。 任何人都可以告诉我我做错了什么

This is what I am getting in my submit callback



render() {
    const { fields, handleSubmit, submitting, buttonWrapper, btnText } = this.props;
    return (
      <form name="AddEvent" onSubmit={handleSubmit}>
        {fields.map(field => (
          <div className={field.wrapperClass}>
            <Field
              name={field.name}
              type={field.type || 'text'}
              component={mapComponentClass(field.componentClass)}
              validate={mapValidators(field.validate)}
              props={field.inputProps}
              label={field.label}
            />
          </div>
        ))}
        <div className="form-submit-wrap container">
            <button
              type="submit"
              disabled={submitting}
              className="form-submit"
            >
              {submitting ? 'Submitting' : 'Submit'}
            </button>
          </div>
      </form>
    );
  }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

handleSubmit应该是onSubmit函数的包装器。

试试这样:

<form onSubmit={handleSubmit(onSubmit)}>
</form>

现在onSubmit将收到包含所有表单值的1个参数。

并非您要求它,但作为旁注,如果您愿意,可以从onSubmit函数中触发提交验证错误,如:

throw ReduxForm.SubmissionError({name: 'There\'s something wrong in the name field'});

...由于您的Ajax调用导致name无效。