Skip to content

Commit

Permalink
fix case of object default
Browse files Browse the repository at this point in the history
  • Loading branch information
olzraiti committed May 19, 2017
1 parent a706347 commit 742c679
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function computeDefaults(schema, parentDefaults, formData, definitions) {
definitions
);
return acc;
}, {});
}, schema.default || {});
return formData ? mergeObjects(formData, defaultFilled) : defaultFilled;
}
default: {
Expand Down
12 changes: 12 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,18 @@ describe("utils", () => {
arr: [{ defaultFilled: true }],
});
});

it("should work for object default", () => {
const schema = {
type: "object",
properties: {},
default: {
foo: "bar",
},
};

expect(getDefaultFormState(schema, {})).eql({ foo: "bar" });
});
});

describe("asNumber()", () => {
Expand Down

0 comments on commit 742c679

Please sign in to comment.