-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPeopleForm.js
More file actions
44 lines (36 loc) · 1.08 KB
/
PeopleForm.js
File metadata and controls
44 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, {Component} from 'react'
import {reduxForm, Field} from 'redux-form'
import validator from 'email-validator'
import ErrorField from '../common/ErrorField'
class PeopleForm extends Component {
render() {
return (
<div>
<form onSubmit={this.props.handleSubmit}>
<div>
First-name: <Field name='firstName' component={ErrorField}/>
</div>
<div>
Last-name: <Field name='lastName' component={ErrorField}/>
</div>
<div>
Email: <Field name='email' component={ErrorField}/>
</div>
<input type='submit' />
</form>
</div>
)
}
}
const validate = ({firstName, lastName, email}) => {
const errors = {}
if (!firstName) errors.firstName = 'First name is required'
if (!lastName) errors.lastName = 'Last name is required'
if (!email) errors.email = 'email is a required field'
if (email && !validator.validate(email)) errors.email = 'incorrect email format'
return errors
}
export default reduxForm({
form: 'people',
validate
})(PeopleForm)