File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class App extends Component {
6
6
constructor ( ) {
7
7
super ( ) ;
8
8
this . state = {
9
+ formIsValid : false , //we will use this to track the overall form validity
9
10
formControls : {
10
11
name : {
11
12
value : '' ,
@@ -37,8 +38,14 @@ class App extends Component {
37
38
38
39
updatedControls [ name ] = updatedFormElement ;
39
40
41
+ let formIsValid = true ;
42
+ for ( let inputIdentifier in updatedControls ) {
43
+ formIsValid = updatedControls [ inputIdentifier ] . valid && formIsValid ;
44
+ }
45
+
40
46
this . setState ( {
41
- formControls : updatedControls
47
+ formControls : updatedControls ,
48
+ formIsValid
42
49
} ) ;
43
50
}
44
51
@@ -51,16 +58,17 @@ class App extends Component {
51
58
return (
52
59
< div className = "App" >
53
60
< h2 > Form helper</ h2 >
54
- < form onSubmit = { this . formSubmitHandler } >
55
- < label htmlFor = "name" > Name{ ' ' } </ label >
61
+ < form onSubmit = { this . formSubmitHandler } autoComplete = "off" >
56
62
< TextInput
57
- id = "name "
63
+ label = "Name "
58
64
name = "name"
59
65
placeholder = { this . state . formControls . name . placeholder }
60
66
value = { this . state . formControls . name . value }
61
67
onChange = { this . changeHandler }
68
+ touched = { this . state . formControls . name . touched }
69
+ valid = { this . state . formControls . name . valid }
62
70
/>
63
- < button type = "submit" > Submit </ button >
71
+ < button type = "submit" className = "btn-submit" disabled = { ! this . state . formIsValid } > Submit </ button >
64
72
</ form >
65
73
</ div >
66
74
) ;
You can’t perform that action at this time.
0 commit comments