@@ -10,6 +10,28 @@ function asyncValidate(data, dispatch) {
1010 return dispatch ( isValidEmail ( data ) ) ;
1111}
1212
13+ /* eslint-disable react/prop-types */
14+ const Input = ( {
15+ input, label, type, showAsyncValidating, className, styles,
16+ meta : { touched, error, dirty, active, visited, asyncValidating }
17+ } ) => (
18+ < div className = { `form-group ${ error && touched ? 'has-error' : '' } ` } >
19+ < label htmlFor = { input . name } className = "col-sm-2" > { label } </ label >
20+ < div className = { `col-sm-8 ${ styles . inputGroup } ` } >
21+ { showAsyncValidating && asyncValidating && < i className = { `fa fa-cog fa-spin ${ styles . cog } ` } /> }
22+ < input { ...input } type = { type } className = { className } id = { input . name } />
23+ { error && touched && < div className = "text-danger" > { error } </ div > }
24+ < div className = { styles . flags } >
25+ { dirty && < span className = { styles . dirty } title = "Dirty" > D</ span > }
26+ { active && < span className = { styles . active } title = "Active" > A</ span > }
27+ { visited && < span className = { styles . visited } title = "Visited" > V</ span > }
28+ { touched && < span className = { styles . touched } title = "Touched" > T</ span > }
29+ </ div >
30+ </ div >
31+ </ div >
32+ ) ;
33+ /* eslint-enable react/prop-types */
34+
1335@reduxForm ( {
1436 form : 'survey' ,
1537 validate : surveyValidation ,
@@ -41,26 +63,6 @@ class SurveyForm extends Component {
4163 active : null
4264 }
4365
44- renderInput = ( {
45- input, label, type, showAsyncValidating, className, styles,
46- meta : { touched, error, dirty, active, visited, asyncValidating }
47- } ) => (
48- < div className = { `form-group ${ error && touched ? 'has-error' : '' } ` } >
49- < label htmlFor = { input . name } className = "col-sm-2" > { label } </ label >
50- < div className = { `col-sm-8 ${ styles . inputGroup } ` } >
51- { showAsyncValidating && asyncValidating && < i className = { `fa fa-cog fa-spin ${ styles . cog } ` } /> }
52- < input { ...input } type = { type } className = { className } id = { input . name } />
53- { error && touched && < div className = "text-danger" > { error } </ div > }
54- < div className = { styles . flags } >
55- { dirty && < span className = { styles . dirty } title = "Dirty" > D</ span > }
56- { active && < span className = { styles . active } title = "Active" > A</ span > }
57- { visited && < span className = { styles . visited } title = "Visited" > V</ span > }
58- { touched && < span className = { styles . touched } title = "Touched" > T</ span > }
59- </ div >
60- </ div >
61- </ div >
62- ) ;
63-
6466 render ( ) {
6567 const {
6668 asyncValidating,
@@ -80,7 +82,7 @@ class SurveyForm extends Component {
8082 < Field
8183 name = "name"
8284 type = "text"
83- component = { this . renderInput }
85+ component = { Input }
8486 label = "Full Name"
8587 className = "form-control"
8688 styles = { styles }
@@ -89,7 +91,7 @@ class SurveyForm extends Component {
8991 < Field
9092 name = "email"
9193 type = "text"
92- component = { this . renderInput }
94+ component = { Input }
9395 label = "Email"
9496 className = "form-control"
9597 styles = { styles }
@@ -99,7 +101,7 @@ class SurveyForm extends Component {
99101 < Field
100102 name = "occupation"
101103 type = "text"
102- component = { this . renderInput }
104+ component = { Input }
103105 label = "Occupation"
104106 className = "form-control"
105107 styles = { styles }
@@ -108,7 +110,7 @@ class SurveyForm extends Component {
108110 < Field
109111 name = "currentlyEmployed"
110112 type = "checkbox"
111- component = { this . renderInput }
113+ component = { Input }
112114 label = "Currently Employed?"
113115 styles = { styles }
114116 />
0 commit comments