Skip to content

Commit

Permalink
Checkbox and Toggle return value at mount
Browse files Browse the repository at this point in the history
otherwise, they only reported a value of toggled before submit
  • Loading branch information
Me committed Oct 14, 2015
1 parent e1ce0f3 commit a4a1500
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
17 changes: 12 additions & 5 deletions formsy-material-ui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Checkbox
{...this.props}
onCheck={this.handleValueChange}
value={this.getValue()} />
ref={(c) => this._checkbox = c}
onCheck={this.handleValueChange} />
);
}
});
Expand Down Expand Up @@ -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 (
<Toggle
{...this.props}
onToggle={this.handleValueChange}
value={this.getValue()} />
ref={(c) => this._toggle = c}
onToggle={this.handleValueChange} />
);
}
});
Expand Down
27 changes: 21 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
});

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }));
}
});

Expand Down

0 comments on commit a4a1500

Please sign in to comment.