Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit ae19c16

Browse files
committed
implemented login example
1 parent 2f5fab4 commit ae19c16

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

examples/Login/index.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,69 @@
11
import React from 'react';
22
import Form from '@cat-react/form/Form';
33
import BasicInput from '../components/BasicInput';
4+
import autoBind from 'auto-bind';
45

56
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+
636
render() {
737
return (
8-
<Form>
38+
<Form onValid={this.onValid}
39+
onInvalid={this.onInvalid}
40+
onValidSubmit={this.onValidSubmit}>
941
<h1>Login</h1>
1042
<BasicInput label="Email address"
1143
name="email"
1244
type="email"
1345
value=""
1446
validations={{isRequired: true, isEmail: true}}
47+
validationErrors={{
48+
isEmail: 'Enter a valid email address.'
49+
}}
1550
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>
1767
</Form>
1868
);
1969
};

tests/Input.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Input', () => {
4545
wrapper.setProps({validations: {isRequired: true}});
4646
expect(instance.isRequired()).toBe(true);
4747

48-
wrapper.instance().onBlur();
48+
wrapper.instance().touch();
4949
wrapper.update();
5050
expect(instance.isPristine()).toBe(false);
5151
});

0 commit comments

Comments
 (0)