-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix for clearing errors after updating and submitting form #2536
Conversation
This also addresses the PR #2123 with addition of tests. |
Bumps [tar](https://github.com/npm/node-tar) from 4.4.16 to 4.4.19. - [Release notes](https://github.com/npm/node-tar/releases) - [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md) - [Commits](isaacs/node-tar@v4.4.16...v4.4.19) --- updated-dependencies: - dependency-name: tar dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com>
…orm into fix/formErrors
errorSchema: {}, | ||
schemaValidationErrors: [], | ||
schemaValidationErrorSchema: {}, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a UI test like
react-jsonschema-form/packages/core/test/Form_test.js
Lines 630 to 634 in 739a303
expect(node.querySelector("#root_children_0_name")).to.not.exist; | |
Simulate.click(node.querySelector(".array-item-add button")); | |
expect(node.querySelector("#root_children_0_name")).to.exist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new UI tests as requested checking for generated HTML
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address these changes and then feel free to merge
Reasons for making this change
There is a bug in the core form (and other variations) where by the form continues to render errors even after the user has fixed them and submitted the form.
The reason this happens is as follows, when the user submits the form, onSubmit handler is called. If validation is enabled then, the handler runs validation functions to check for errors,
If errors are generated then the form State is updated with the new errors
If errors are not generated then the state is updated as follows
As we see in the later state update
schemaValidationErrors
andschemaValidationErrorSchema
are not being updated.This creates a problem because the state for the form is derived using the above values as seen here
What this does is that when the last error is fixed on re-submission of the form, the state is calculated from the stale values of schemaValidationErrors & schemaValidationErrorSchema
We fix this by updating the schemaValidationErrors & schemaValidationErrorSchema in the state when form is submitted with errors fixed.
If this is related to existing tickets, include links to them as well. Use the syntax
fixes #[issue number]
(ex:fixes #123
).Checklist
Tests
Failing test due to this bug
Passing test after fix