Skip to content
This repository was archived by the owner on Jan 27, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common-mobx-form",
"version": "0.0.22",
"version": "0.0.24",
"description": "",
"main": "./lib",
"module": "./src",
Expand Down
32 changes: 14 additions & 18 deletions src/fields/CheckboxField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,32 @@ import {observer} from 'mobx-react';

@observer
class CheckboxField extends React.Component {
static defaultProps = {
field: {
id: ''
}
};

static propTypes = {
placeholder: PropTypes.string,
field: PropTypes.object,
classContainer: PropTypes.string,
};

constructor(props) {
super(props);
this.inputId = Math.random().toString(36).substring(7);
}

handleChange() {
const {field} = this.props;
field.value = !field.value;
if (field.onChange) {
field.onChange(field.value);
}
}
get inputId() {
return this.props.field.id || Math.random().toString(36).substring(7);
}

render() {
const {placeholder, field, classContainer, tabIndex} = this.props;
return (
<div className={classContainer}>
<input id={this.inputId}
type='checkbox'
<input type='checkbox'
tabIndex={tabIndex}
{...field.bind({checked: field.value})} />
<label for={this.inputId}
className='label_check'
onClick={() => this.handleChange()}>
{...field.bind({checked: field.value})}
id={this.inputId} />
<label htmlFor={this.inputId}
className='label_check'>
<i className='icon'/>
<span className='f_small'>{placeholder}</span>
</label>
Expand Down