1
1
import React , { Component } from 'react' ;
2
2
import './App.css' ;
3
3
import { TextInput , Validate } from './utils/form_helpers' ;
4
+ import { inputType } from './utils/Constants' ;
4
5
5
6
class App extends Component {
6
7
constructor ( ) {
@@ -13,9 +14,16 @@ class App extends Component {
13
14
placeholder : 'What is your name' ,
14
15
valid : false ,
15
16
touched : false ,
17
+ errorMessage : "" ,
16
18
validationRules : {
17
- minLength : 3 ,
18
- isRequired : true
19
+
20
+ isRequired : {
21
+ message : "Name is required" ,
22
+ } ,
23
+ minLength : {
24
+ value : 2 ,
25
+ message : "Min length is required" ,
26
+ }
19
27
}
20
28
}
21
29
}
@@ -34,7 +42,10 @@ class App extends Component {
34
42
} ;
35
43
updatedFormElement . value = value ;
36
44
updatedFormElement . touched = true ;
37
- updatedFormElement . valid = Validate ( value , updatedFormElement . validationRules ) ;
45
+ const { isValid, message } = Validate ( value , updatedFormElement . validationRules ) ;
46
+
47
+ updatedFormElement . valid = isValid ;
48
+ updatedFormElement . errorMessage = message ;
38
49
39
50
updatedControls [ name ] = updatedFormElement ;
40
51
@@ -63,6 +74,8 @@ class App extends Component {
63
74
label = "Name"
64
75
name = "name"
65
76
placeholder = { this . state . formControls . name . placeholder }
77
+ // helpText="Name must be greater than 6 character"
78
+ errorMessage = { this . state . formControls . name . errorMessage }
66
79
value = { this . state . formControls . name . value }
67
80
onChange = { this . changeHandler }
68
81
touched = { this . state . formControls . name . touched }
0 commit comments