File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change
1
+ import ValidationContext from '@react-form-fields/core/components/ValidationContext' ;
2
+ import * as React from 'react' ;
3
+
4
+ interface IProps {
5
+ onSubmit : ( valid : boolean ) => void ;
6
+ }
7
+
8
+ export class FormValidation extends React . PureComponent < IProps > {
9
+ private validationContext : ValidationContext ;
10
+
11
+ private bindValidationContext = ( validationContext : ValidationContext ) : void => {
12
+ this . validationContext = validationContext ;
13
+ }
14
+
15
+ private onSubmit = ( e ?: React . SyntheticEvent ) => {
16
+ e && e . preventDefault && e . preventDefault ( ) ;
17
+
18
+ const isValid = this . validationContext . isValid ( true ) ;
19
+ this . props . onSubmit ( isValid ) ;
20
+ }
21
+
22
+ reset = ( ) => {
23
+ this . validationContext . reset ( ) ;
24
+ }
25
+
26
+ render ( ) {
27
+ return (
28
+ < form noValidate onSubmit = { this . onSubmit } >
29
+ < ValidationContext ref = { this . bindValidationContext } >
30
+ { this . props . children }
31
+ </ ValidationContext >
32
+ </ form >
33
+ ) ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change 10
10
" validation" ,
11
11
" material"
12
12
],
13
- "version" : " 1.8.9 " ,
13
+ "version" : " 1.9.0 " ,
14
14
"main" : " ./dist/index.js" ,
15
15
"types" : " ./dist/index.d.ts" ,
16
16
"license" : " MIT" ,
32
32
"prepare" : " yarn tsc"
33
33
},
34
34
"dependencies" : {
35
- "@material-ui/core" : " >=3.0.0" ,
36
- "@material-ui/icons" : " >=3.0.0" ,
37
35
"@react-form-fields/core" : " >=1.1.0" ,
38
36
"autosuggest-highlight" : " >=3.0.0" ,
39
37
"date-fns" : " >=2.0.0-alpha.16" ,
40
38
"material-ui-pickers" : " >=1.0.0-rc.13" ,
41
- "react" : " >=16.3.0" ,
42
39
"react-autosuggest" : " >=9.0.0" ,
43
40
"react-color" : " >=2.14.1" ,
44
41
"tslib" : " >=1.9.2" ,
50
47
"react" : " >=16.0.0"
51
48
},
52
49
"devDependencies" : {
50
+ "react" : " >=16.3.0" ,
51
+ "@material-ui/core" : " >=3.0.0" ,
52
+ "@material-ui/icons" : " >=3.0.0" ,
53
53
"@types/react-autosuggest" : " 9.3.5" ,
54
54
"@types/react-color" : " 2.13.6" ,
55
55
"@types/validatorjs" : " 3.7.1" ,
You can’t perform that action at this time.
0 commit comments