1
1
import React from 'react'
2
2
import { Field , reduxForm } from 'redux-form'
3
- import TextField from 'material-ui/TextField'
4
- import { RadioButton , RadioButtonGroup } from 'material-ui/RadioButton'
5
- import Checkbox from 'material-ui/Checkbox'
6
- import SelectField from 'material-ui/SelectField'
3
+ import { RadioButton } from 'material-ui/RadioButton'
7
4
import MenuItem from 'material-ui/MenuItem'
8
5
import asyncValidate from './asyncValidate'
6
+ import adapter from 'redux-form-material-ui'
9
7
10
8
const validate = values => {
11
9
const errors = { }
@@ -21,71 +19,74 @@ const validate = values => {
21
19
return errors
22
20
}
23
21
24
- const renderTextField = props => (
25
- < TextField hintText = { props . label }
26
- floatingLabelText = { props . label }
27
- errorText = { props . touched && props . error }
28
- { ...props }
29
- />
30
- )
31
-
32
- const renderCheckbox = props => (
33
- < Checkbox label = { props . label }
34
- checked = { props . value ? true : false }
35
- onCheck = { props . onChange } />
36
- )
37
-
38
- const renderSelectField = props => (
39
- < SelectField
40
- floatingLabelText = { props . label }
41
- errorText = { props . touched && props . error }
42
- { ...props }
43
- onChange = { ( event , index , value ) => props . onChange ( value ) } >
44
- </ SelectField >
45
- )
46
-
47
22
const MaterialUiForm = props => {
48
23
const { handleSubmit, pristine, reset, submitting } = props
49
24
return (
50
25
< form onSubmit = { handleSubmit } >
51
26
< div >
52
- < Field name = "firstName" component = { renderTextField } label = "First Name" />
27
+ < Field name = "firstName"
28
+ component = "TextField"
29
+ hintText = "First Name"
30
+ floatingLabelText = "First Name" />
53
31
</ div >
54
32
< div >
55
- < Field name = "lastName" component = { renderTextField } label = "Last Name" />
33
+ < Field
34
+ name = "lastName"
35
+ component = "TextField"
36
+ hintText = "Last Name"
37
+ floatingLabelText = "Last Name" />
56
38
</ div >
57
39
< div >
58
- < Field name = "email" component = { renderTextField } label = "Email" />
40
+ < Field
41
+ name = "email"
42
+ component = "TextField"
43
+ hintText = "Email"
44
+ floatingLabelText = "Email" />
59
45
</ div >
60
46
< div >
61
- < Field name = "sex" component = { RadioButtonGroup } >
62
- < RadioButton value = "male" label = "male " />
63
- < RadioButton value = "female" label = "female " />
47
+ < Field name = "sex" component = " RadioButtonGroup" >
48
+ < RadioButton value = "male" label = "Male " />
49
+ < RadioButton value = "female" label = "Female " />
64
50
</ Field >
65
51
</ div >
66
52
< div >
67
- < Field name = "favoriteColor" component = { renderSelectField } label = "Favorite Color" >
53
+ < Field
54
+ name = "favoriteColor"
55
+ component = "SelectField"
56
+ hintText = "Favorite Color"
57
+ floatingLabelText = "Favorite Color" >
68
58
< MenuItem value = { 'ff0000' } primaryText = "Red" />
69
59
< MenuItem value = { '00ff00' } primaryText = "Green" />
70
60
< MenuItem value = { '0000ff' } primaryText = "Blue" />
71
61
</ Field >
72
62
</ div >
73
63
< div >
74
- < Field name = "employed" component = { renderCheckbox } label = "Employed" />
64
+ < Field name = "employed" component = "Checkbox" label = "Employed" />
65
+ </ div >
66
+ < div >
67
+ < Field name = "married" component = "Toggle" label = "Married" labelPosition = "right" />
75
68
</ div >
76
69
< div >
77
- < Field name = "notes" component = { renderTextField } label = "Notes" multiLine = { true } rows = { 2 } />
70
+ < Field
71
+ name = "notes"
72
+ component = "TextField"
73
+ hintText = "Notes"
74
+ floatingLabelText = "Notes"
75
+ multiLine = { true }
76
+ rows = { 2 } />
78
77
</ div >
79
78
< div >
80
79
< button type = "submit" disabled = { pristine || submitting } > Submit</ button >
81
- < button type = "button" disabled = { pristine || submitting } onClick = { reset } > Clear Values</ button >
80
+ < button type = "button" disabled = { pristine || submitting } onClick = { reset } > Clear Values
81
+ </ button >
82
82
</ div >
83
83
</ form >
84
84
)
85
85
}
86
86
87
87
export default reduxForm ( {
88
88
form : 'MaterialUiForm' , // a unique identifier for this form
89
+ adapter,
89
90
validate,
90
91
asyncValidate
91
92
} ) ( MaterialUiForm )
0 commit comments