-
Notifications
You must be signed in to change notification settings - Fork 92
/
checkbox.js
68 lines (56 loc) · 1.66 KB
/
checkbox.js
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
/*jshint node:true */
'use strict';
var React = require('react');
var Formsy = require('formsy-react');
var ComponentMixin = require('./mixins/component');
var Row = require('./row');
var Checkbox = React.createClass({
mixins: [Formsy.Mixin, ComponentMixin],
getDefaultProps: function() {
return {
label: '',
rowLabel: '',
value: false
};
},
changeValue: function(event) {
var target = event.currentTarget;
this.setValue(target.checked);
this.props.onChange(this.props.name, target.checked);
},
renderElement: function() {
return (
<div className="checkbox">
<label>
<input
ref="element"
{...this.props}
id={this.getId()}
type="checkbox"
checked={this.getValue() === true}
onChange={this.changeValue}
disabled={this.isFormDisabled() || this.props.disabled}
/> {this.props.label}
</label>
</div>
);
},
render: function() {
var element = this.renderElement();
if (this.getLayout() === 'elementOnly') {
return element;
}
return (
<Row
{...this.getRowProperties()}
label={this.props.rowLabel}
htmlFor={this.getId()}
>
{element}
{this.renderHelp()}
{this.renderErrorMessage()}
</Row>
);
}
});
module.exports = Checkbox;