@@ -25,7 +25,7 @@ class Contact extends Component {
2525 handleCancel ( ) {
2626 console . log ( 'handleCancel' )
2727 this . setState ( this . state . cachedForm )
28- this . setState ( { cachedForm : { } } )
28+ // this.setState({ cachedForm: {} })
2929 this . setState ( { showForm : false } )
3030 }
3131
@@ -37,7 +37,7 @@ class Contact extends Component {
3737 console . log ( 'handleEdit' )
3838 this . setPropsToLocalState ( )
3939 this . setState ( { showForm : true } )
40- this . setState ( { cachedForm : this . props . contact } )
40+ // this.setState({ cachedForm: this.props.contact })
4141 }
4242
4343 handleInputChange ( event ) {
@@ -55,9 +55,10 @@ class Contact extends Component {
5555
5656 handleSubmit ( formValues ) {
5757 console . log ( 'handleSubmit' )
58- this . setState ( { showForm : false } )
58+
59+ console . log ( formValues ) ;
5960 this . props . updateContactData ( formValues )
60-
61+ this . setState ( { showForm : false } )
6162 }
6263
6364 sanitizeToJustNumbers ( value ) {
@@ -69,13 +70,15 @@ class Contact extends Component {
6970 }
7071
7172 setPropsToLocalState ( ) {
72- const keys = [ 'name' , 'relation' , 'address' , 'phone' , 'city' , 'postal' , 'state' , 'country' , 'email' ]
73+ const keys = [ 'id' , ' name', 'relation' , 'address' , 'phone' , 'city' , 'postal' , 'state' , 'country' , 'email' ]
7374
7475 keys . forEach ( ( keyName ) => {
7576 let value
76-
77- if ( keyName === 'phone' ) {
77+ // Make switch statement
78+ if ( keyName === 'phone' ) {
7879 value = this . sanitizeToJustNumbers ( this . props . contact [ keyName ] . toString ( ) )
80+ } else if ( keyName === 'id' ) {
81+ value = this . props . contact [ keyName ]
7982 } else {
8083 value = this . props . contact [ keyName ]
8184 }
@@ -129,7 +132,7 @@ class Contact extends Component {
129132 noValidate >
130133 < table className = 'table' >
131134 < tr >
132- < td > < strong > Name: </ strong >
135+ < td >
133136 < FormsyInput value = { this . state . name }
134137 onChange = { this . handleInputChange }
135138 name = 'name'
@@ -145,7 +148,7 @@ class Contact extends Component {
145148 } }
146149 required />
147150 </ td >
148- < td > < strong > Relation: </ strong >
151+ < td >
149152 < FormsyInput value = { this . state . relation }
150153 onChange = { this . handleInputChange }
151154 name = 'relationship'
@@ -163,7 +166,7 @@ class Contact extends Component {
163166 </ td >
164167 </ tr >
165168 < tr >
166- < td > < strong > Address: </ strong >
169+ < td >
167170 < FormsyInput value = { this . state . address }
168171 onChange = { this . handleInputChange }
169172 name = 'address'
@@ -178,7 +181,7 @@ class Contact extends Component {
178181 minLength : 'You must enter at least 2 characters'
179182 } }
180183 required /> </ td >
181- < td > < strong > Phone: </ strong >
184+ < td >
182185 < FormsyMaskedInput mask = { [ '(' , / [ 1 - 9 ] / , / \d / , / \d / , ')' , ' ' , / \d / , / \d / , / \d / , '-' , / \d / , / \d / , / \d / , / \d / ] }
183186 value = { this . state . phone }
184187 onChange = { this . handleInputChange }
@@ -195,7 +198,7 @@ class Contact extends Component {
195198 required /> </ td >
196199 </ tr >
197200 < tr >
198- < td > < strong > City: </ strong >
201+ < td >
199202 < FormsyInput value = { this . state . city }
200203 onChange = { this . handleInputChange }
201204 name = 'city'
@@ -213,7 +216,7 @@ class Contact extends Component {
213216 </ td >
214217 </ tr >
215218 < tr >
216- < td > < strong > State: </ strong >
219+ < td >
217220 < FormsyInput value = { this . state . state }
218221 onChange = { this . handleInputChange }
219222 name = 'state'
@@ -229,9 +232,45 @@ class Contact extends Component {
229232 } }
230233 required />
231234 </ td >
235+
236+ < td >
237+ < FormsyInput
238+ value = { this . state . postal }
239+ onChange = { this . handleInputChange }
240+ name = 'postal'
241+ label = 'Postal'
242+ validations = { {
243+ maxLength : 10 ,
244+ minLength : 4
245+ } }
246+ validationErrors = { {
247+ isDefaultRequiredValue : 'Valid postal is required' ,
248+ maxLength : 'You must not enter more than 10 characters' ,
249+ minLength : 'You must enter at least 4 characters'
250+ } }
251+ required />
252+ </ td >
232253 </ tr >
233254 < tr >
234- < td > < strong > Email:</ strong >
255+ < td >
256+ < FormsyInput value = { this . state . country }
257+ onChange = { this . handleInputChange }
258+ name = 'country'
259+ label = 'Country'
260+ validations = { {
261+ maxLength : 30 ,
262+ minLength : 2
263+ } }
264+ validationErrors = { {
265+ isDefaultRequiredValue : 'Valid country is required' ,
266+ maxLength : 'You must not enter more than 30 characters' ,
267+ minLength : 'You must enter at least 2 characters'
268+ } }
269+ required />
270+ </ td >
271+ </ tr >
272+ < tr >
273+ < td >
235274 < FormsyInput value = { this . state . email }
236275 onChange = { this . handleInputChange }
237276 name = 'email'
@@ -248,6 +287,17 @@ class Contact extends Component {
248287 required />
249288 </ td >
250289 </ tr >
290+ < tr >
291+ < td >
292+ < FormsyInput type = 'hidden'
293+ value = { this . state . id }
294+ onChange = { this . handleInputChange }
295+ name = 'id'
296+ label = 'ID'
297+
298+ required />
299+ </ td >
300+ </ tr >
251301 </ table >
252302
253303 < button className = 'btn btn-default btn-sm' type = 'submit' > SAVE</ button >
0 commit comments