1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_forms/input_checkbox.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
2015-06-01 13:02:53 +02:00
import React from 'react';
import AlertMixin from '../../mixins/alert_mixin';
2015-06-01 13:02:53 +02:00
let InputCheckbox = React.createClass({
propTypes: {
submitted: React.PropTypes.bool.isRequired,
required: React.PropTypes.string.isRequired,
label: React.PropTypes.string.isRequired
},
2015-06-01 13:02:53 +02:00
mixins: [AlertMixin],
2015-06-01 13:02:53 +02:00
getInitialState() {
return {
value: null,
alerts: null // needed in AlertMixin
2015-06-01 13:02:53 +02:00
};
},
2015-06-01 13:02:53 +02:00
handleChange(event) {
this.setState({value: event.target.value});
},
2015-06-01 13:02:53 +02:00
render() {
let alerts = (this.props.submitted) ? null : this.state.alerts;
return (
<div className="form-group">
{alerts}
<div className="input-checkbox-ascribe">
<div className="checkbox">
<label>
<input
type="checkbox"
required={this.props.required}
onChange={this.handleChange}
/>
{this.props.label}
</label>
</div>
</div>
</div>
);
}
});
export default InputCheckbox;