反应表单内的 HandleSubimt 上未发生验证

问题描述

如前所述,我有一些需要验证的字段,但它并没有在 react-form 上发生。我正在学习“Modern React with Redux”课程,我有以下代码,其中包含必须针对空值进行验证的 redux 表单:

import React from "react";
import {Field,reduxForm} from 'redux-form';

class StreamCreate extends React.Component {
    renderInput({input,label,Meta}){
        console.log(Meta)
        return (
            <div className="field">
                <label>{label}</label>
                <input {...input}/>
            </div>
        )
    }

    onSubmit(formValues){
        console.log(formValues);
    }
    
    render(){
        return(
            <form onSubmit={this.props.handleSubmit(this.onSubmit)} className="ui form">
                <Field name="title" component={this.renderInput} 
                    label="enter title"
                />
                <Field name="description" component={this.renderInput} 
                    label="enter description"
                />
                <button className="ui button primary">Submit</button>
            </form>
        )
    }
} 

const validate = (formValues) => { // This is not running!
    const errors = {};

    if (!formValues.title){
        errors.title = "you must enter a title";
    }
    if (!formValues.description){
        errors.description = "you must enter a description";
    }
}

export default reduxForm({
    form: 'streamCreate',validate // I followed the example to the T and checked the documentation
})(StreamCreate);

文档如下:

https://redux-form.com/8.2.2/examples/syncvalidation/

任何帮助将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)