Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript react和验证器的Redux表单_Javascript_Reactjs_Redux_Redux Form - Fatal编程技术网

Javascript react和验证器的Redux表单

Javascript react和验证器的Redux表单,javascript,reactjs,redux,redux-form,Javascript,Reactjs,Redux,Redux Form,我第一次使用redux表单,在处理同步验证器时遇到了一些问题 实际上,我有以下组件: import React, {Component, PropTypes} from 'react'; import {Field} from 'redux-form'; /** * The SignupForm class definition */ export default class SignupForm extends Component { /** * The SignupFo

我第一次使用redux表单,在处理同步验证器时遇到了一些问题

实际上,我有以下组件:

import React, {Component, PropTypes} from 'react';
import {Field} from 'redux-form';
/**
 * The SignupForm class definition
 */
export default class SignupForm extends Component {
    /**
     * The SignupForm props type
     */
    static propTypes = {
        handleSubmit: PropTypes.func,
    }

    /**
     * Render the SignupForm
     */
    render() {
        console.log(this.props); // nothing available concerning the error
        const {
            handleSubmit
        } = this.props;
        return (
            <form onSubmit={handleSubmit}>
                <Field name="email" component="input" required placeholder="Email" type="text"/>
                <Field name="emailConfirmation" component="input" required placeholder="Confirm your email" type="text"/>
                <Field name="password" component="input" required placeholder="Password" type="password"/>
                <Field name="passwordConfirmation" component="input" required placeholder="Confirm your password" type="password"/>
                <button type="submit" className="signup">Signup</button>
            </form>
        );
    }
}
并使用reduxForm函数映射redux表单和验证程序:

import SignupForm from './../../components/signupForm/signupForm';
import validate from './signupForm.validators';
import {reduxForm} from 'redux-form';
export default reduxForm({
    form: 'signup',
    validate
})(SignupForm);
我的问题

当我在我的验证器中console.log返回语句上的errors对象时,我很可能会有错误,告诉我我的电子邮件地址不一样

但是当我在我的组件中输入console.log this.props时,我可以看到一个具有一些redux表单属性和方法的对象,但是错误对象是未定义的

我可能把事情弄错了,但我不知道怎么做,为什么


有什么帮助吗?

当您的validate函数被调用时,您正在创建一个对象“errors”并返回它,因此redux表单将使用它将错误注入到相应的字段中

在您的情况下:您的字段“email”应该在props:meta:{error:'两个电子邮件地址不相同'}

你确定这没有发生吗

你查过了吗

据我所知,你只能在现场进行

meta.error:字符串[可选]

如果此字段的值未通过验证,则此字段的错误。同步、异步和提交验证错误将在此处报告


当您的validate函数被调用时,您正在创建一个对象“errors”并返回它,因此redux表单将使用它将错误注入到相应的字段中

在您的情况下:您的字段“email”应该在props:meta:{error:'两个电子邮件地址不相同'}

你确定这没有发生吗

你查过了吗

据我所知,你只能在现场进行

meta.error:字符串[可选]

如果此字段的值未通过验证,则此字段的错误。同步、异步和提交验证错误将在此处报告


哦,这只是一个现场水平?如果我需要在表单级别实现,该怎么办?我想是的,如果需要这样做,您可能希望保存对这些字段的引用,并从父级创建可调用函数。或者您可以将其存储在redux中并使用选择器。根据需要,您可以在
\u error
键处创建表单级错误。i、 e.
错误。_error='整个表单有问题'哦,这只是一个字段级别?如果我需要在表单级别实现,该怎么办?我想是的,如果需要这样做,您可能希望保存对这些字段的引用,并从父级创建可调用函数。或者您可以将其存储在redux中并使用选择器。根据需要,您可以在
\u error
键处创建表单级错误。i、 e.
错误。_error='整个表单有问题'
import SignupForm from './../../components/signupForm/signupForm';
import validate from './signupForm.validators';
import {reduxForm} from 'redux-form';
export default reduxForm({
    form: 'signup',
    validate
})(SignupForm);