Reactjs 提交上的Redux表单没有发生任何事情

Reactjs 提交上的Redux表单没有发生任何事情,reactjs,redux-form,Reactjs,Redux Form,我想问一下,我的代码遗漏了什么。提交表单时,submitForm功能似乎不起作用/触发。我无法从表单字段中获取值。这是我的密码: import React from 'react'; import { reduxForm,reset, Field } from 'redux-form'; class FormProfile extends React.Component { submitForm(formProps){ console.log(formProps);

我想问一下,我的代码遗漏了什么。提交表单时,
submitForm
功能似乎不起作用/触发。我无法从表单字段中获取值。这是我的密码:

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

class FormProfile extends React.Component {
    submitForm(formProps){
        console.log(formProps);
    }

    render(){

        const { error, handleSubmit } = this.props;

        return (
            <form onSubmit={this.submitForm.bind(this)}>
                <Row>
                    <Col lg={6}>
                        <Field  name="name" type="text" component={TextBoxComponent}  placeholder="Compay Name" label="* Company Name" required />
                        <Field  name="website" type="text" component={TextBoxComponent}  placeholder="www.yourdomain.com" label="Website" />
                        <Field  name="email" type="text" component={TextBoxComponent}  placeholder="How can we contact your Company" label="* Contact Email" required />
                    </Col>
                </Row>
            </form>
        );
    }
}

const form = reduxForm({
    form: 'CreateCompanyProfileForm',
    validate
});

function validate(formProps){
    const error = {};

    return error;
}

export default (form(FormProfile));
从“React”导入React;
从'redux form'导入{reduxForm,reset,Field};
类FormProfile扩展了React.Component{
提交表单(formProps){
console.log(formProps);
}
render(){
const{error,handleSubmit}=this.props;
返回(
);
}
}
const form=reduxForm({
表单:“CreateCompanyProfileForm”,
验证
});
函数验证(formProps){
常量错误={};
返回误差;
}
导出默认值(表单(FormProfile));
文本框组件

import React from "react";
class TextBoxComponent extends React.Component {
    render(){
        return (
            <div className="form-group">
                <label className="control-label">{this.props.label}</label>
                { this.props.sublabel !== undefined ?
                    <em className="text-info"> { this.props.sublabel }</em>
                :null}
                <input { ...this.props } type={this.props.type} placeholder={this.props.placeholder} className="form-control"/>
                { this.props.required && <span className="text-error"></span> }
            </div>
        );
    }
}
export default TextBoxComponent;
从“React”导入React;
类TextBoxComponent扩展了React.Component{
render(){
返回(
{this.props.label}
{this.props.sublabel!==未定义?
{this.props.sublabel}
:null}
{this.props.required&&}
);
}
}
导出默认TextBoxComponent;

您应该修改此行:

<form onSubmit={this.submitForm.bind(this)}>
然后,您可以创建一个新组件来包装redux表单组件:

class SamplePage extends React.Component {
  handleSubmit = (values) => {
    // Do something with the form values
    console.log(values);
  }
  render() {
    return (
      <FormProfile onSubmit={this.handleSubmit} />
    );
  }
}
class SamplePage扩展了React.Component{
handleSubmit=(值)=>{
//对表单值执行一些操作
console.log(值);
}
render(){
返回(
);
}
}
无论如何,您应该检查Redux表单文档中的示例:

 submitForm(formProps){
    console.log(formProps);
 }
class SamplePage extends React.Component {
  handleSubmit = (values) => {
    // Do something with the form values
    console.log(values);
  }
  render() {
    return (
      <FormProfile onSubmit={this.handleSubmit} />
    );
  }
}