diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e580f0038..920ccfdeb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ should change the heading of the (upcoming) version to include a major version b # 5.21.2 +## @rjsf/core + +- Updated `SchemaField` to pass `required` flag to `_AnyOfField`/`_OneOfField` +- Updated `Form` to deal with null objects in `filterErrorsBasedOnSchema()`, fixing [#4306](https://github.com/rjsf-team/react-jsonschema-form/issues/4306) + ## Dev / docs / playground - Updated the `custom-widgets-fields.md` to add examples of wrapping a widget/field diff --git a/packages/core/src/components/Form.tsx b/packages/core/src/components/Form.tsx index 0fd28b30c7..07b3ee6bbf 100644 --- a/packages/core/src/components/Form.tsx +++ b/packages/core/src/components/Form.tsx @@ -38,6 +38,7 @@ import { import _forEach from 'lodash/forEach'; import _get from 'lodash/get'; import _isEmpty from 'lodash/isEmpty'; +import _isNil from 'lodash/isNil'; import _pick from 'lodash/pick'; import _toPath from 'lodash/toPath'; @@ -621,18 +622,18 @@ export default class Form< if (resolvedSchema?.type !== 'object' && resolvedSchema?.type !== 'array') { filteredErrors.__errors = schemaErrors.__errors; } - // Removing undefined and empty errors. - const filterUndefinedErrors = (errors: any): ErrorSchema => { + // Removing undefined, null and empty errors. + const filterNilOrEmptyErrors = (errors: any): ErrorSchema => { _forEach(errors, (errorAtKey, errorKey: keyof typeof errors) => { - if (errorAtKey === undefined) { + if (_isNil(errorAtKey)) { delete errors[errorKey]; } else if (typeof errorAtKey === 'object' && !Array.isArray(errorAtKey.__errors)) { - filterUndefinedErrors(errorAtKey); + filterNilOrEmptyErrors(errorAtKey); } }); return errors; }; - return filterUndefinedErrors(filteredErrors); + return filterNilOrEmptyErrors(filteredErrors); } /** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the diff --git a/packages/core/src/components/fields/SchemaField.tsx b/packages/core/src/components/fields/SchemaField.tsx index ee7bd23ca5..c7b8db77e5 100644 --- a/packages/core/src/components/fields/SchemaField.tsx +++ b/packages/core/src/components/fields/SchemaField.tsx @@ -317,6 +317,7 @@ function SchemaFieldRender @@ -340,6 +341,7 @@ function SchemaFieldRender