This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +53
-3
lines changed Expand file tree Collapse file tree 2 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import Form from '@cat-react/form/Form' ;
3
3
import BasicInput from '../components/BasicInput' ;
4
+ import autoBind from 'auto-bind' ;
4
5
5
6
export default class App extends React . Component {
7
+ constructor ( props ) {
8
+ super ( props ) ;
9
+
10
+ autoBind ( this ) ;
11
+
12
+ this . state = {
13
+ canSubmit : false ,
14
+ values : null
15
+ }
16
+ }
17
+
18
+ onValid ( ) {
19
+ this . setState ( {
20
+ canSubmit : true
21
+ } ) ;
22
+ }
23
+
24
+ onInvalid ( ) {
25
+ this . setState ( {
26
+ canSubmit : false
27
+ } ) ;
28
+ }
29
+
30
+ onValidSubmit ( values ) {
31
+ this . setState ( {
32
+ values : values
33
+ } ) ;
34
+ }
35
+
6
36
render ( ) {
7
37
return (
8
- < Form >
38
+ < Form onValid = { this . onValid }
39
+ onInvalid = { this . onInvalid }
40
+ onValidSubmit = { this . onValidSubmit } >
9
41
< h1 > Login</ h1 >
10
42
< BasicInput label = "Email address"
11
43
name = "email"
12
44
type = "email"
13
45
value = ""
14
46
validations = { { isRequired : true , isEmail : true } }
47
+ validationErrors = { {
48
+ isEmail : 'Enter a valid email address.'
49
+ } }
15
50
placeholder = "Enter email" />
16
- < button type = "submit" className = "btn btn-primary" > Login</ button >
51
+ < BasicInput label = "Password"
52
+ name = "password"
53
+ type = "password"
54
+ value = ""
55
+ validations = { { isRequired : true , minLength : 3 } }
56
+ validationErrors = { {
57
+ isRequired : 'Enter your password.' ,
58
+ minLength : 'A password must contain minimum 3 characters.'
59
+ } }
60
+ placeholder = "Enter password" />
61
+ < button type = "submit"
62
+ className = "btn btn-primary"
63
+ disabled = { ! this . state . canSubmit } > Login</ button >
64
+ < div className = "alert alert-light" role = "alert" >
65
+ Valid Submitted Values: { JSON . stringify ( this . state . values ) }
66
+ </ div >
17
67
</ Form >
18
68
) ;
19
69
} ;
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ describe('Input', () => {
45
45
wrapper . setProps ( { validations : { isRequired : true } } ) ;
46
46
expect ( instance . isRequired ( ) ) . toBe ( true ) ;
47
47
48
- wrapper . instance ( ) . onBlur ( ) ;
48
+ wrapper . instance ( ) . touch ( ) ;
49
49
wrapper . update ( ) ;
50
50
expect ( instance . isPristine ( ) ) . toBe ( false ) ;
51
51
} ) ;
You can’t perform that action at this time.
0 commit comments