From d2ac1c1713903c8c204030ec403b6579a7823445 Mon Sep 17 00:00:00 2001 From: Tomasz Durka Date: Fri, 20 Sep 2024 21:11:00 +0200 Subject: [PATCH 1/3] Fix: Pass required props to anyof/oneof field components (#4303) --- packages/core/src/components/fields/SchemaField.tsx | 2 ++ 1 file changed, 2 insertions(+) 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 From 4cb834266187d95a0421292c7bdb7746466a9d8c Mon Sep 17 00:00:00 2001 From: Heath C <51679588+heath-freenome@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:34:22 -0700 Subject: [PATCH 2/3] Chore: Updating changelog with missing info (#4309) Updated `CHANGELOG.md` to add details for the simple fix provided in #4303 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e580f0038..cfba570c5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ 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` + ## Dev / docs / playground - Updated the `custom-widgets-fields.md` to add examples of wrapping a widget/field From d3af3078f642957e66c8066ab60a3bfa45707445 Mon Sep 17 00:00:00 2001 From: Heath C <51679588+heath-freenome@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:48:25 -0700 Subject: [PATCH 3/3] fix: deal with null objects in errors in Form.filterErrorsBasedOnSchema() (#4310) * fix: deal with null objects in errors in Form.filterErrorsBasedOnSchema() Fixes #4306 by using `lodash.isNil()` instead of comparing to `undefined` - Updated `Form.filterErrorsBasedOnSchema()` to use lodash `isNil()` to check if the key is either null or undefined - Updated the `CHANGELOG.md` accordingly * - Made name more correct --- CHANGELOG.md | 1 + packages/core/src/components/Form.tsx | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfba570c5a..920ccfdeb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ should change the heading of the (upcoming) version to include a major version b ## @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 diff --git a/packages/core/src/components/Form.tsx b/packages/core/src/components/Form.tsx index aa8bc60ab5..7df7891f71 100644 --- a/packages/core/src/components/Form.tsx +++ b/packages/core/src/components/Form.tsx @@ -37,6 +37,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'; @@ -603,18 +604,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