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

Allow to change additionalProperties to falsy values #2540

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 packages/core/src/components/fields/ObjectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ObjectField extends Component {

onPropertyChange = (name, addedByAdditionalProperties = false) => {
return (value, errorSchema) => {
if (!value && addedByAdditionalProperties) {
if (value === undefined && addedByAdditionalProperties) {
// Don't set value = undefined for fields added by
// additionalProperties. Doing so removes them from the
// formData, which causes them to completely disappear
Expand Down
51 changes: 51 additions & 0 deletions packages/core/test/ObjectField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,5 +866,56 @@ describe("ObjectField", () => {
formData: { first: "" },
});
});

it("should change content of value input to boolean false", () => {
const { node, onChange } = createFormComponent({
schema: {
...schema,
additionalProperties: true,
},
formData: { first: true },
});

Simulate.change(node.querySelector("#root_first"), {
target: { checked: false },
});

sinon.assert.calledWithMatch(onChange.lastCall, {
formData: { first: false },
});
});

it("should change content of value input to number 0", () => {
const { node, onChange } = createFormComponent({
schema: {
...schema,
additionalProperties: true,
},
formData: { first: 1 },
});

Simulate.change(node.querySelector("#root_first"), {
target: { value: 0 },
});

sinon.assert.calledWithMatch(onChange.lastCall, {
formData: { first: 0 },
});
});

it("should change content of value input to null", () => {
const { node, onChange } = createFormComponent({
schema,
formData: { first: "str" },
});

Simulate.change(node.querySelector("#root_first"), {
target: { value: null },
});

sinon.assert.calledWithMatch(onChange.lastCall, {
formData: { first: null },
});
});
});
});