Search code examples
reactjsreduxredux-form

Getting undefined for Field name in reduxform


I have redux form in a class component and for some reason when I console log the formValues I am getting undefined what is the problem?

class CreateTeamBox  extends Component{

    handleFormSubmit({name}){
        console.log(name);

      }

    renderError = ({ touched, error}) => {
        if(touched && error) {
            return(
                <div>{error}</div>
            );
        }
    }

    renderInput = ({input, label, type, meta}) => {



        return(
            <div className={styles.formGroup}>
                <label>{label}</label>
                <input  {...input} />
                <div className={styles.errorWrapper}>
                        {this.renderError(meta)}
                </div>

            </div>

        );

    }

    render() {
        const {handleSubmit, error} = this.props ;
        return(

            <div className={styles.createTeamBox}>
                <div className={styles.titleWrapper}>
                    <h2>create team</h2>
                </div>
                <div className={styles.bodyWrapper}>
                        <div className={styles.submitErrorWrapper}>
                            {error ?  <Error error={error} /> : null}   
                        </div>
                        <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
                            <Field name="name" component={this.renderInput} label="name" />
                             <button className={styles.button} type="submit" >create</button>
                        </form>
                </div>
            </div>

)
    }
}


const validate = (formValues) => {
    console.log(formValues.name);
    const name = formValues.name;


     const errors = validateForm(name);


    return errors;



}

export default reduxForm({
    form: 'createTeamForm',
    validate

})(CreateTeamBox);

I have other reduxform in the same given project with different names, is it causing the problem? Im not sure why it is happening as I havecopied most of the coe from working reduxform in the given project .


Solution

  • the default value of formValues will be empty object, after enter some data to the field then you can get the value, or you can pass the value by using initialValues