Skip to content

Commit d3af307

Browse files
fix: deal with null objects in errors in Form.filterErrorsBasedOnSchema() (rjsf-team#4310)
* fix: deal with null objects in errors in Form.filterErrorsBasedOnSchema() Fixes rjsf-team#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
1 parent 4cb8342 commit d3af307

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ should change the heading of the (upcoming) version to include a major version b
2121
## @rjsf/core
2222

2323
- Updated `SchemaField` to pass `required` flag to `_AnyOfField`/`_OneOfField`
24+
- Updated `Form` to deal with null objects in `filterErrorsBasedOnSchema()`, fixing [#4306](https://github.com/rjsf-team/react-jsonschema-form/issues/4306)
2425

2526
## Dev / docs / playground
2627

packages/core/src/components/Form.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import _forEach from 'lodash/forEach';
3838
import _get from 'lodash/get';
3939
import _isEmpty from 'lodash/isEmpty';
40+
import _isNil from 'lodash/isNil';
4041
import _pick from 'lodash/pick';
4142
import _toPath from 'lodash/toPath';
4243

@@ -603,18 +604,18 @@ export default class Form<
603604
if (resolvedSchema?.type !== 'object' && resolvedSchema?.type !== 'array') {
604605
filteredErrors.__errors = schemaErrors.__errors;
605606
}
606-
// Removing undefined and empty errors.
607-
const filterUndefinedErrors = (errors: any): ErrorSchema<T> => {
607+
// Removing undefined, null and empty errors.
608+
const filterNilOrEmptyErrors = (errors: any): ErrorSchema<T> => {
608609
_forEach(errors, (errorAtKey, errorKey: keyof typeof errors) => {
609-
if (errorAtKey === undefined) {
610+
if (_isNil(errorAtKey)) {
610611
delete errors[errorKey];
611612
} else if (typeof errorAtKey === 'object' && !Array.isArray(errorAtKey.__errors)) {
612-
filterUndefinedErrors(errorAtKey);
613+
filterNilOrEmptyErrors(errorAtKey);
613614
}
614615
});
615616
return errors;
616617
};
617-
return filterUndefinedErrors(filteredErrors);
618+
return filterNilOrEmptyErrors(filteredErrors);
618619
}
619620

620621
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the

0 commit comments

Comments
 (0)