forked from zabute/formsy-semantic-ui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckboxExamples.js
More file actions
85 lines (76 loc) · 2.07 KB
/
CheckboxExamples.js
File metadata and controls
85 lines (76 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { Component } from 'react';
import Form from 'formsy-react';
import { Container, Button, Label, Segment } from 'semantic-ui-react';
import { Checkbox } from '../src';
// <Radio/> has similar behavior and props
const styles = {
root: {
marginTop: 18,
},
};
export default class CheckboxExamples extends Component {
onValidSubmit = (formData) => alert(JSON.stringify(formData)); // eslint-disable-line
render() {
const errorLabel = <Label color="red" pointing="left"/>;
const requiredCheckbox = (
<Checkbox
name="checkbox"
label="I agree to everything"
required
validations="isTrue"
validationErrors={{
isTrue: 'This is non-negotiable',
isDefaultRequiredValue: 'You\'ll have to check this box',
}}
errorLabel={ errorLabel }
style={ styles.formElement }
/>
);
const defaultChecked = (
<Checkbox
name="defaultChecked"
label="Remember Me"
required
defaultChecked
validations="isTrue"
validationErrors={{
isTrue: 'You\'ll have to check this box',
isDefaultRequiredValue: 'You\'ll have to check this box',
}}
errorLabel={ errorLabel }
style={ styles.formElement }
/>
);
return (
<Container style={ styles.root }>
<Form
noValidate
onValidSubmit={ this.onValidSubmit }
ref={ref => this.form = ref }
>
<Segment>
<h5> Required Checkbox</h5>
{ requiredCheckbox }
</Segment>
<Segment>
<h5> Default Checked </h5>
{ defaultChecked }
</Segment>
<Button
content="Submit"
style={ styles.formElement }
color="orange"
/>
<Button
type="button"
onClick={ () => this.form.reset({
defaultChecked: true,
})}
content="Reset"
color="black"
/>
</Form>
</Container>
);
}
}