Search code examples
reactjsreact-reduxredux-formreact-redux-form

Validate a Field with Redux-form


I try learn how to works with redux-form and I have a little probleme. For example, I have a Field component like that:

<Field
  name='individual.email'
  id="email"
  component={ renderInput }
  placeholder='test'
/>

In validate.js I have something like that:

 if ( !values.individual.email ) {
            errors.individual.email = 'Required'
        }

But I have the error :

TypeError: Cannot set property 'email' of undefined

If I change the name of my Field by only 'email' it is works fine.. Any idea of what I do wrong when my Field is 'individual.email' ?


Solution

  • try this

     if ( values.individual && !values.individual.email ) {
                errors.individual.email = 'Required'
            }