Skip to content

Commit

Permalink
Propagate events through props when handlers exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
magicalcows committed Feb 9, 2016
1 parent 173888f commit 3e0c432
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ var FormsyTime = FMUI.FormsyTime;
var FormsyToggle = FMUI.FormsyToggle;
```

### Events

As of 0.3.8 events that are used in components (eg, have a binding to their own internal method) are checked for
in `this.props`, and when found, are called with Material-UI's proposed
[Standardized Callback Signatures](https://github.com/callemall/material-ui/issues/2957). An example usage of this
would be to use an `onChange` for the FormsySelect and receive notifications when it changes.

### Examples

#### Example App
Expand Down
1 change: 1 addition & 0 deletions src/FormsyCheckbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let FormsyCheckbox = React.createClass({

handleValueChange: function (event, value) {
this.setValue(value);
if (this.props.onCheck) this.props.onCheck(event, value);
},

componentDidMount: function () {
Expand Down
1 change: 1 addition & 0 deletions src/FormsyDate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let FormsyDate = React.createClass({

handleValueChange: function (event, value) {
this.setValue(value);
if (this.props.onChange) this.props.onChange(event, value);
},

_setMuiComponentAndMaybeFocus: _setMuiComponentAndMaybeFocus,
Expand Down
1 change: 1 addition & 0 deletions src/FormsyRadioGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let FormsyRadioGroup = React.createClass({

componentDidMount: function () {
this.setValue(this._muiComponent.getSelectedValue());
if (this.props.onChange) this.props.onChange(event, value);
},

_setMuiComponentAndMaybeFocus: _setMuiComponentAndMaybeFocus,
Expand Down
1 change: 1 addition & 0 deletions src/FormsySelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let FormsySelect = React.createClass({
handleChange: function (event, index, value) {
this.setValue(value);
this.setState({hasChanged: true});
if (this.props.onChange) this.props.onChange(event, value, index);
},

_setMuiComponentAndMaybeFocus: _setMuiComponentAndMaybeFocus,
Expand Down
4 changes: 4 additions & 0 deletions src/FormsyText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ let FormsyText = React.createClass({
handleChange: function handleChange(event) {
if(this.getErrorMessage() != null){
this.setValue(event.currentTarget.value);
if (this.props.onChange) this.props.onChange(event, event.currentTarget.value);
}
else{
if (this.isValidValue(event.target.value)) {
this.setValue(event.target.value);
if (this.props.onChange) this.props.onChange(event, event.target.value);
}
else{
this.setState({
_value: event.currentTarget.value,
_isPristine: false
});
if (this.props.onChange) this.props.onChange(event, event.currentTarget.value);
}
}
},
Expand All @@ -37,6 +40,7 @@ let FormsyText = React.createClass({

handleEnterKeyDown: function handleEnterKeyDown(event) {
this.setValue(event.currentTarget.value);
if (this.props.onEnterKeyDown) this.props.onEnterKeyDown(event, event.currentTarget.value);
},

_setMuiComponentAndMaybeFocus: _setMuiComponentAndMaybeFocus,
Expand Down
1 change: 1 addition & 0 deletions src/FormsyTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let FormsyTime = React.createClass({

handleValueChange: function (event, value) {
this.setValue(value);
if (this.props.onChange) this.props.onChange(event, value);
},

_setMuiComponentAndMaybeFocus: _setMuiComponentAndMaybeFocus,
Expand Down
1 change: 1 addition & 0 deletions src/FormsyToggle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let FormsyToggle = React.createClass({

handleValueChange: function (event, value) {
this.setValue(value);
if (this.props.onToggle) this.props.onToggle(event, value);
},

componentDidMount: function () {
Expand Down

0 comments on commit 3e0c432

Please sign in to comment.