'react redux form give values undefinde
I made this form help of react-redux-form. but the form handelSubmit console.log() is undefined and do not show any validation and the check button not be checked. I tried but can not find where is my mistake. I am new and trying to learning react. please help me to find my mistake
Currently am passing the data to the Form component but it didn't find in my value field in Redux form. I would like to do the concept in redux forms. Here I attached my code
import {Button, FormGroup, Label, Col} from 'reactstrap';
import {Form, Control, Errors, actions} from 'react-redux-form';
const requierd = val => val && val.length;
const isNumber = val => !isNaN(Number(val));
const validEmail = val => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(val);
class Contact extends Component{
handelSubmit = values => {
console.log(values)
}
render(){
return(
<div className="container">
<div className="row row-content" style={{paddingLeft:"20px", textAlign:'left'}}>
<div className='col-12'>
<h3>Send your feedback</h3>
</div>
<div className='col-12 col-md-7'>
<Form model='.feedback' onSubmit={values=>this.handelSubmit(values)}>
<FormGroup row>
<Label htmlFor='name' md={2} > Name</Label>
<Col md={10}>
<Control.text
model='.name'
name='name'
placeholder='Name'
className='form-control'
validators={{requierd}}
/>
<Errors
className='text-danger'
model='.name'
show='touch'
massage={{
requierd: 'Write some thing'
}} />
</Col>
</FormGroup>
<FormGroup row>
<Label htmlFor='telnum' md={2} >Contact Tel.</Label>
<Col md={10}>
<Control.text
model='.telnum'
name='telnum'
placeholder='Tel. Number'
className='form-control'
validators={{requierd, isNumber}}
/>
<Errors
className='text-danger'
model='.telnum'
show='touch'
massage={{
requierd: 'Write some thing',
isNumber: 'This is not a valid number'
}} />
</Col>
</FormGroup>
<FormGroup row>
<Label htmlFor='email' md={2} >Email</Label>
<Col md={10}>
<Control.text
model = '.email'
name='email'
placeholder='Email'
className='form-control'
validators={{requierd, validEmail}}
/>
<Errors
className='text-danger'
model='.email'
show='touch'
massage={{
requierd: 'Write some thing',
validEmail: 'This is not a valid Email'
}} />
</Col>
</FormGroup>
<FormGroup row>
<Col md={{size:3, offset:2}}>
<FormGroup check>
<Label check>
<Control.checkbox
model='.agree'
name='agree'
className='form-check-input'
/>
<strong>May we contact you ?</strong>
</Label>
</FormGroup>
</Col>
<Col md={{size:2, offset:1}}>
<Control.select
model="contactType"
name='contactType'
className='form-control'
>
<option>Tel.</option>
<option>Email</option>
</Control.select>
</Col>
</FormGroup>
<FormGroup row>
<Label htmlFor="massage" md={2}> Your Feedback</Label>
<Col md={10}>
<Control.textarea
model='.massage'
name="massage"
row ="12"
className='form-control'
validators={{requierd}}
/>
<Errors
className='text-danger'
model='.massage'
show='touch'
massage={{
requierd: 'Write some thing'
}} />
</Col>
</FormGroup>
<FormGroup row>
<Col md={{size:10, offset:2}}>
<Button type="submit" color="secondary" >
Send Feedback
</Button>
</Col>
</FormGroup>
</Form>
</div>
</div>
</div>
)
}
}
export default Contact;```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
