Fix: Cannot reset value unless truthy

This commit is contained in:
Semigradsky 2016-04-21 13:05:47 +03:00
parent d84397906b
commit 6767a6b9eb
2 changed files with 25 additions and 1 deletions

View File

@ -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();

View File

@ -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) {