Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(onchange): Form onChange prop honors dot notation nesting, matching submit prop #48

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ var Formsy = function (_React$Component) {
_this.validate = function (component) {
// Trigger onChange
if (_this.state.canChange) {
_this.props.onChange(_this.getCurrentValues(), _this.isChanged());
_this.props.onChange(_this.getModel(), _this.isChanged());
}

var validation = _this.runValidation(component);
Expand Down
2 changes: 1 addition & 1 deletion release/formsy-react.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/formsy-react.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Formsy extends React.Component {
validate = (component) => {
// Trigger onChange
if (this.state.canChange) {
this.props.onChange(this.getCurrentValues(), this.isChanged());
this.props.onChange(this.getModel(), this.isChanged());
}

const validation = this.runValidation(component);
Expand Down
34 changes: 34 additions & 0 deletions tests/Formsy-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,40 @@ export default {

},

'onChange should honor dot notation transformations': function (test) {

const hasChanged = sinon.spy();
class TestForm extends React.Component {
state = {
showInput: false
}
addInput() {
this.setState({
showInput: true
})
}
render() {
return (
<Formsy onChange={hasChanged}>
{
this.state.showInput ?
<TestInput name="parent.child" value="test"/>
:
null
}
</Formsy>);
}
}

const form = TestUtils.renderIntoDocument(<TestForm/>);
form.addInput();
immediate(() => {
test.deepEqual(hasChanged.args[0][0], {parent: {child: 'test'}});
test.done();
});

},

'Update a form': {

'should allow elements to check if the form is disabled': function (test) {
Expand Down