Skip to content

Commit

Permalink
Merge branch 'main' into fix-wrong-allOf-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Sep 27, 2024
2 parents fe9b06a + d3af307 commit 1971163
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<T> => {
// Removing undefined, null and empty errors.
const filterNilOrEmptyErrors = (errors: any): ErrorSchema<T> => {
_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
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/fields/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
schemaUtils.retrieveSchema(isObject(_schema) ? (_schema as S) : ({} as S), formData)
)}
registry={registry}
required={required}
schema={schema}
uiSchema={uiSchema}
/>
Expand All @@ -340,6 +341,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
schemaUtils.retrieveSchema(isObject(_schema) ? (_schema as S) : ({} as S), formData)
)}
registry={registry}
required={required}
schema={schema}
uiSchema={uiSchema}
/>
Expand Down

0 comments on commit 1971163

Please sign in to comment.