From 5ac75591a946596e741129a13a8472b4fcd511de Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Wed, 18 Apr 2018 11:58:54 +0200 Subject: [PATCH] ES6 assets/js/src/form/fields/checkbox.jsx --- assets/js/src/form/fields/checkbox.jsx | 83 ++++++++++++-------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/assets/js/src/form/fields/checkbox.jsx b/assets/js/src/form/fields/checkbox.jsx index c833d52b3a..3bc2c68134 100644 --- a/assets/js/src/form/fields/checkbox.jsx +++ b/assets/js/src/form/fields/checkbox.jsx @@ -1,48 +1,43 @@ -define([ - 'react', -], -( - React -) => { - const FormFieldCheckbox = React.createClass({ - onValueChange: function onValueChange(e) { - e.target.value = this.checkbox.checked ? '1' : '0'; - return this.props.onValueChange(e); - }, - render: function render() { - if (this.props.field.values === undefined) { - return false; - } +import React from 'react'; - // isChecked will be true only if the value is "1" - // it will be false in case value is "0" or empty - const isChecked = !!(Number(this.props.item[this.props.field.name])); - const options = Object.keys(this.props.field.values).map( - (value, index) => ( -

- -

- ) - ); +const FormFieldCheckbox = React.createClass({ + onValueChange: function onValueChange(e) { + e.target.value = this.checkbox.checked ? '1' : '0'; + return this.props.onValueChange(e); + }, + render: function render() { + if (this.props.field.values === undefined) { + return false; + } - return ( -
- { options } -
- ); - }, - }); + // isChecked will be true only if the value is "1" + // it will be false in case value is "0" or empty + const isChecked = !!(Number(this.props.item[this.props.field.name])); + const options = Object.keys(this.props.field.values).map( + value => ( +

+ +

+ ) + ); - return FormFieldCheckbox; + return ( +
+ { options } +
+ ); + }, }); + +export default FormFieldCheckbox;