implement checkboxes properly
@@ -10,13 +10,27 @@ import React from 'react'
import Checkbox from 'material-ui/Checkbox'
-const ToggleButton = ({ value, meta, onChange }) => (
+export default class ToggleButton extends React.Component {
+ constructor (props, ...args) {
+ super(props, ...args)
+ this.state = { checked: props.value === '1' }
+ }
+
+ handleCheck = (evt, checked) => {
+ const { onChange } = this.props
+ this.setState({ checked })
+ onChange(checked ? '1' : '0')
+ }
+
+ render () {
+ const { value, meta } = this.props
+ return (
<Checkbox
label={meta && meta.description}
- checked={value == 'true'}
- onCheck={(evt, checked) => onChange(String(checked))}
+ checked={this.state.checked}
+ onCheck={this.handleCheck}
style={{ display: 'inline-block', width: 'auto' }}
/>
)
-
-export default ToggleButton
+ }
+}
