ES6 assets/js/src/form/fields/checkbox.jsx

This commit is contained in:
Amine Ben hammou
2018-04-18 11:58:54 +02:00
parent 6892dbea91
commit 5ac75591a9

View File

@@ -1,10 +1,6 @@
define([ import React from 'react';
'react',
], const FormFieldCheckbox = React.createClass({
(
React
) => {
const FormFieldCheckbox = React.createClass({
onValueChange: function onValueChange(e) { onValueChange: function onValueChange(e) {
e.target.value = this.checkbox.checked ? '1' : '0'; e.target.value = this.checkbox.checked ? '1' : '0';
return this.props.onValueChange(e); return this.props.onValueChange(e);
@@ -18,8 +14,8 @@ define([
// it will be false in case value is "0" or empty // it will be false in case value is "0" or empty
const isChecked = !!(Number(this.props.item[this.props.field.name])); const isChecked = !!(Number(this.props.item[this.props.field.name]));
const options = Object.keys(this.props.field.values).map( const options = Object.keys(this.props.field.values).map(
(value, index) => ( value => (
<p key={`checkbox-${index}`}> <p key={`checkbox-${value}`}>
<label htmlFor={this.props.field.name}> <label htmlFor={this.props.field.name}>
<input <input
ref={(c) => { this.checkbox = c; }} ref={(c) => { this.checkbox = c; }}
@@ -42,7 +38,6 @@ define([
</div> </div>
); );
}, },
});
return FormFieldCheckbox;
}); });
export default FormFieldCheckbox;