Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ should change the heading of the (upcoming) version to include a major version b
-->
# 6.1.1

## @rjsf/core

- Updated `ObjectField` to get errors and formData by wrapping `name` in brackets to prevent names that have dots in them incorrectly getting data from a lower level, fixing [#3846](https://github.com/rjsf-team/react-jsonschema-form/issues/3846)

## @rjsf/shadcn

- Updated `package.json` to copy css files to new `resources` directory
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/fields/ObjectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
required={isRequired<S>(schema, name)}
schema={get(schema, [PROPERTIES_KEY, name], {}) as S}
uiSchema={fieldUiSchema}
errorSchema={get(errorSchema, name)}
errorSchema={get(errorSchema, [name])}
fieldPathId={childFieldPathId}
formData={get(formData, name)}
formData={get(formData, [name])}
handleKeyRename={handleKeyRename}
handleRemoveProperty={handleRemoveProperty}
addedByAdditionalProperties={addedByAdditionalProperties}
Expand Down
35 changes: 35 additions & 0 deletions packages/core/test/ObjectField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,41 @@ describe('ObjectField', () => {
errorMessages = node.querySelectorAll('#root_foo__error');
expect(errorMessages).to.have.length(0);
});

it('should not copy errors when name has dotted-path similar to real property', () => {
const schema = {
type: 'object',
properties: {
'Foo.Bar': {
type: 'string',
minLength: 5,
},
Foo: {
type: 'object',
properties: {
Bar: {
type: 'string',
minLength: 2,
},
},
},
},
};
const formData = {
'Foo.Bar': 'FooBar',
Foo: {
Bar: 'B',
},
};
const { node } = createFormComponent({ schema, formData });
// click submit
submitForm(node);
console.log(node.innerHTML);
const fooDotBarErrors = node.querySelectorAll('#root_Foo.Bar__error');
expect(fooDotBarErrors).to.have.length(0);
const fooBarErrors = node.querySelectorAll('#root_Foo_Bar__error');
expect(fooBarErrors).to.have.length(1);
});
});

describe('fields ordering', () => {
Expand Down