Skip to content

Commit

Permalink
Fix: Cannot reset value unless truthy
Browse files Browse the repository at this point in the history
  • Loading branch information
Semigradsky committed Apr 21, 2016
1 parent d843979 commit 6767a6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Formsy.Form = React.createClass({
resetModel: function (data) {
this.inputs.forEach(component => {
var name = component.props.name;
if (data && data[name]) {
if (data && data.hasOwnProperty(name)) {
component.setValue(data[name]);
} else {
component.resetValue();
Expand Down
24 changes: 24 additions & 0 deletions tests/Formsy-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,30 @@ export default {

},

'should be able to reset the form to empty values': function (test) {

const TestForm = React.createClass({
render() {
return (
<Formsy.Form>
<TestInput name="foo" value="42" type="checkbox" />
<button type="submit">Save</button>
</Formsy.Form>
);
}
});
const form = TestUtils.renderIntoDocument(<TestForm/>);
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
const formsyForm = TestUtils.findRenderedComponentWithType(form, Formsy.Form);

formsyForm.reset({
foo: ''
});
test.equal(input.getValue(), '');
test.done();

},

'.isChanged()': {

'initially returns false': function (test) {
Expand Down

0 comments on commit 6767a6b

Please sign in to comment.