Skip to content

Commit 247d3cc

Browse files
committed
fix form level onchange not honoring dot notation nesting
1 parent 5da2ba5 commit 247d3cc

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ var Formsy = function (_React$Component) {
300300
_this.validate = function (component) {
301301
// Trigger onChange
302302
if (_this.state.canChange) {
303-
_this.props.onChange(_this.getCurrentValues(), _this.isChanged());
303+
_this.props.onChange(_this.getModel(), _this.isChanged());
304304
}
305305

306306
var validation = _this.runValidation(component);

release/formsy-react.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/formsy-react.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class Formsy extends React.Component {
272272
validate = (component) => {
273273
// Trigger onChange
274274
if (this.state.canChange) {
275-
this.props.onChange(this.getCurrentValues(), this.isChanged());
275+
this.props.onChange(this.getModel(), this.isChanged());
276276
}
277277

278278
const validation = this.runValidation(component);

tests/Formsy-spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,40 @@ export default {
415415

416416
},
417417

418+
'onChange should honor dot notation transformations': function (test) {
419+
420+
const hasChanged = sinon.spy();
421+
class TestForm extends React.Component {
422+
state = {
423+
showInput: false
424+
}
425+
addInput() {
426+
this.setState({
427+
showInput: true
428+
})
429+
}
430+
render() {
431+
return (
432+
<Formsy onChange={hasChanged}>
433+
{
434+
this.state.showInput ?
435+
<TestInput name="parent.child" value="test"/>
436+
:
437+
null
438+
}
439+
</Formsy>);
440+
}
441+
}
442+
443+
const form = TestUtils.renderIntoDocument(<TestForm/>);
444+
form.addInput();
445+
immediate(() => {
446+
test.deepEqual(hasChanged.args[0][0], {parent: {child: 'test'}});
447+
test.done();
448+
});
449+
450+
},
451+
418452
'Update a form': {
419453

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

0 commit comments

Comments
 (0)