From a4a15000e60aab506928d6af1501ae407266ccdd Mon Sep 17 00:00:00 2001 From: Me Date: Wed, 14 Oct 2015 20:48:44 +0100 Subject: [PATCH] Checkbox and Toggle return value at mount otherwise, they only reported a value of toggled before submit --- formsy-material-ui.jsx | 17 ++++++++++++----- index.js | 27 +++++++++++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/formsy-material-ui.jsx b/formsy-material-ui.jsx index c402421..72628d2 100644 --- a/formsy-material-ui.jsx +++ b/formsy-material-ui.jsx @@ -28,13 +28,16 @@ let FormComponentMixin = { let FormsyCheckbox = React.createClass({ mixins: [ Formsy.Mixin, FormComponentMixin ], - render: function () { + componentDidMount: function () { + this.setValue(this._checkbox.isChecked()); + }, + render: function () { return ( + ref={(c) => this._checkbox = c} + onCheck={this.handleValueChange} /> ); } }); @@ -119,12 +122,16 @@ let FormsyTime = React.createClass({ let FormsyToggle = React.createClass({ mixins: [ Formsy.Mixin, FormComponentMixin ], + componentDidMount: function () { + this.setValue(this._toggle.isToggled()); + }, + render: function () { return ( + ref={(c) => this._toggle = c} + onToggle={this.handleValueChange} /> ); } }); diff --git a/index.js b/index.js index 91a508a..e522edc 100644 --- a/index.js +++ b/index.js @@ -38,11 +38,18 @@ var FormsyCheckbox = React.createClass({ mixins: [Formsy.Mixin, FormComponentMixin], + componentDidMount: function componentDidMount() { + this.setValue(this._checkbox.isChecked()); + }, + render: function render() { + var _this = this; return React.createElement(Checkbox, _extends({}, this.props, { - onCheck: this.handleValueChange, - value: this.getValue() })); + ref: function (c) { + return _this._checkbox = c; + }, + onCheck: this.handleValueChange })); } }); @@ -80,13 +87,13 @@ var FormsyRadioGroup = React.createClass({ }, render: function render() { - var _this = this; + var _this2 = this; return React.createElement( RadioButtonGroup, _extends({}, this.props, { ref: function (c) { - return _this._radio = c; + return _this2._radio = c; }, onChange: this.handleValueChange }), this.props.children @@ -134,10 +141,18 @@ var FormsyToggle = React.createClass({ mixins: [Formsy.Mixin, FormComponentMixin], + componentDidMount: function componentDidMount() { + this.setValue(this._toggle.isToggled()); + }, + render: function render() { + var _this3 = this; + return React.createElement(Toggle, _extends({}, this.props, { - onToggle: this.handleValueChange, - value: this.getValue() })); + ref: function (c) { + return _this3._toggle = c; + }, + onToggle: this.handleValueChange })); } });