@@ -47,66 +47,36 @@ class SurveyForm extends Component {
47
47
asyncValidating,
48
48
dirty,
49
49
fields : { name, email, occupation} ,
50
- handleBlur,
51
- handleChange,
50
+ active,
52
51
handleSubmit,
53
52
invalid,
54
53
resetForm,
55
54
pristine,
56
55
valid
57
56
} = this . props ;
57
+ const styles = require ( './SurveyForm.scss' ) ;
58
+ const renderInput = ( field , label , showAsyncValidating ) =>
59
+ < div className = { 'form-group' + ( field . error && field . touched ? ' has-error' : '' ) } >
60
+ < label htmlFor = { field . name } className = "col-sm-2" > { label } </ label >
61
+ < div className = { 'col-sm-8 ' + styles . inputGroup } >
62
+ { showAsyncValidating && asyncValidating && < i className = { 'fa fa-cog fa-spin ' + styles . cog } /> }
63
+ < input type = "text" className = "form-control" id = { field . name } { ...field } />
64
+ { field . error && field . touched && < div className = "text-danger" > { field . error } </ div > }
65
+ < div className = { styles . flags } >
66
+ { field . dirty && < span className = { styles . dirty } title = "Dirty" > D</ span > }
67
+ { field . active && < span className = { styles . active } title = "Active" > A</ span > }
68
+ { field . visited && < span className = { styles . visited } title = "Visited" > V</ span > }
69
+ { field . touched && < span className = { styles . touched } title = "Touched" > T</ span > }
70
+ </ div >
71
+ </ div >
72
+ </ div > ;
73
+
58
74
return (
59
75
< div >
60
76
< form className = "form-horizontal" onSubmit = { handleSubmit } >
61
- < div className = { 'form-group' + ( name . error && name . touched ? ' has-error' : '' ) } >
62
- < label htmlFor = "name" className = "col-sm-2" >
63
- Full Name
64
- { name . dirty && < span > *</ span > }
65
- </ label >
66
-
67
- < div className = "col-sm-10" >
68
- < input type = "text"
69
- className = "form-control"
70
- id = "name"
71
- value = { name . value }
72
- onChange = { handleChange ( 'name' ) }
73
- onBlur = { handleBlur ( 'name' ) } />
74
- { name . error && name . touched && < div className = "text-danger" > { name . error } </ div > }
75
- </ div >
76
- </ div >
77
- < div className = { 'form-group' + ( email . error && email . touched ? ' has-error' : '' ) } >
78
- < label htmlFor = "email" className = "col-sm-2" >
79
- Email address
80
- { email . dirty && < span > *</ span > }
81
- </ label >
82
-
83
- < div className = "col-sm-10" >
84
- < input type = "email"
85
- className = "form-control"
86
- id = "email"
87
- value = { email . value }
88
- onChange = { handleChange ( 'email' ) }
89
- onBlur = { handleBlur ( 'email' ) } />
90
- { email . error && email . touched && < div className = "text-danger" > { email . error } </ div > }
91
- { asyncValidating && < div > Validating...</ div > }
92
- </ div >
93
- </ div >
94
- < div className = { 'form-group' + ( occupation . error && occupation . touched ? ' has-error' : '' ) } >
95
- < label htmlFor = "occupation" className = "col-sm-2" >
96
- Occupation
97
- { occupation . dirty && < span > *</ span > }
98
- </ label >
99
-
100
- < div className = "col-sm-10" >
101
- < input type = "text"
102
- className = "form-control"
103
- id = "occupation"
104
- value = { occupation . value }
105
- onChange = { handleChange ( 'occupation' ) }
106
- onBlur = { handleBlur ( 'occupation' ) } />
107
- { occupation . error && occupation . touched && < div className = "text-danger" > { occupation . error } </ div > }
108
- </ div >
109
- </ div >
77
+ { renderInput ( name , 'Full Name' ) }
78
+ { renderInput ( email , 'Email' , true ) }
79
+ { renderInput ( occupation , 'Occupation' ) }
110
80
< div className = "form-group" >
111
81
< div className = "col-sm-offset-2 col-sm-10" >
112
82
< button className = "btn btn-success" onClick = { handleSubmit } >
@@ -123,6 +93,10 @@ class SurveyForm extends Component {
123
93
124
94
< table className = "table table-striped" >
125
95
< tbody >
96
+ < tr >
97
+ < th > Active Field</ th >
98
+ < td > { active } </ td >
99
+ </ tr >
126
100
< tr >
127
101
< th > Dirty</ th >
128
102
< td className = { dirty ? 'success' : 'danger' } > { dirty ? 'true' : 'false' } </ td >
0 commit comments