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

clear errors from "additionalProperties: false" #2631

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ should change the heading of the (upcoming) version to include a major version b
- fixed an issue where all semantic props overwritten when a single [semantic theme-specific prop](https://react-jsonschema-form.readthedocs.io/en/latest/api-reference/themes/semantic-ui/uiSchema/) is passed in ([issue 2619](https://github.com/rjsf-team/react-jsonschema-form/issues/2619)) (https://github.com/rjsf-team/react-jsonschema-form/pull/2590)

# v3.2.2 (upcoming)
## @rjsf/core
- clear errors on formData change when liveOmit=true when "additionalProperties: false" [issue 1507](https://github.com/rjsf-team/react-jsonschema-form/issues/1507) (https://github.com/rjsf-team/react-jsonschema-form/pull/2631)

# v3.2.1

Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"start": "concurrently \"npm:build:* -- --watch\"",
"tdd": "cross-env NODE_ENV=test mocha --require @babel/register --watch --require ./test/setup-jsdom.js test/**/*_test.js",
"test": "cross-env BABEL_ENV=test NODE_ENV=test mocha --require @babel/register --require ./test/setup-jsdom.js test/**/*_test.js",
"test-coverage": "cross-env NODE_ENV=test nyc --reporter=lcov mocha --require @babel/register --require ./test/setup-jsdom.js test/**/*_test.js",
"test-debug": "cross-env NODE_ENV=test mocha --require @babel/register --require ./test/setup-jsdom.js --debug-brk --inspect test/Form_test.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the test-debug to work on dedicated Form_test and commit it by accident.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, it is actually a nice add! I'd suggest keeping it

"test-coverage": "cross-env NODE_ENV=test nyc --reporter=lcov mocha --require @babel/register --require ./test/setup-jsdom.js test/**/*_test.js"
},
"lint-staged": {
"{src,test}/**/*.js": [
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,10 @@ export function toPathSchema(schema, name = "", rootSchema, formData = {}) {
return toPathSchema(_schema, name, rootSchema, formData);
}

if (schema.hasOwnProperty("additionalProperties")) {
if (
schema.hasOwnProperty("additionalProperties") &&
schema.additionalProperties !== false
) {
pathSchema.__rjsf_additionalProperties = true;
}

Expand Down
39 changes: 39 additions & 0 deletions packages/core/test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3193,6 +3193,45 @@ describe("Form omitExtraData and liveOmit", () => {
});
});

it("should remove extra data on change with omitExtraData=true and liveOmit=true if additionalProperties equal false", () => {
const omitExtraData = true;
const liveOmit = true;
const schema = {
type: "object",
properties: {
foo: { type: "string", additionalProperties: false },
bar: { type: "string", additionalProperties: false },
info: {
type: "object",
additionalProperties: false,
properties: {
name: {
type: "string",
additionalProperties: false,
},
},
required: ["name"],
},
},
additionalProperties: false,
};
const formData = {
foo: "foo",
baz: "baz",
info: { majorVersion: "v1123", name: "foofoo" },
};
const { node } = createFormComponent({
schema,
formData,
omitExtraData,
liveOmit,
});

Simulate.submit(node);

expect(node.querySelectorAll(".errors li")).to.have.length.of(0);
});

it("should rename formData key if key input is renamed in a nested object with omitExtraData=true and liveOmit=true", () => {
const { node, onChange } = createFormComponent(
{
Expand Down