Skip to content

Commit b660e28

Browse files
Merge branch 'main' into fix-antd-icons
2 parents 35f9ea7 + ea3b763 commit b660e28

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ should change the heading of the (upcoming) version to include a major version b
1717
-->
1818
# 6.1.1
1919

20+
## @rjsf/core
21+
22+
- 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)
23+
2024
## @rjsf/shadcn
2125

2226
- Updated `package.json` to copy css files to new `resources` directory

packages/core/src/components/fields/ObjectField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
367367
required={isRequired<S>(schema, name)}
368368
schema={get(schema, [PROPERTIES_KEY, name], {}) as S}
369369
uiSchema={fieldUiSchema}
370-
errorSchema={get(errorSchema, name)}
370+
errorSchema={get(errorSchema, [name])}
371371
fieldPathId={childFieldPathId}
372-
formData={get(formData, name)}
372+
formData={get(formData, [name])}
373373
handleKeyRename={handleKeyRename}
374374
handleRemoveProperty={handleRemoveProperty}
375375
addedByAdditionalProperties={addedByAdditionalProperties}

packages/core/test/ObjectField.test.jsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,41 @@ describe('ObjectField', () => {
468468
errorMessages = node.querySelectorAll('#root_foo__error');
469469
expect(errorMessages).to.have.length(0);
470470
});
471+
472+
it('should not copy errors when name has dotted-path similar to real property', () => {
473+
const schema = {
474+
type: 'object',
475+
properties: {
476+
'Foo.Bar': {
477+
type: 'string',
478+
minLength: 5,
479+
},
480+
Foo: {
481+
type: 'object',
482+
properties: {
483+
Bar: {
484+
type: 'string',
485+
minLength: 2,
486+
},
487+
},
488+
},
489+
},
490+
};
491+
const formData = {
492+
'Foo.Bar': 'FooBar',
493+
Foo: {
494+
Bar: 'B',
495+
},
496+
};
497+
const { node } = createFormComponent({ schema, formData });
498+
// click submit
499+
submitForm(node);
500+
console.log(node.innerHTML);
501+
const fooDotBarErrors = node.querySelectorAll('#root_Foo.Bar__error');
502+
expect(fooDotBarErrors).to.have.length(0);
503+
const fooBarErrors = node.querySelectorAll('#root_Foo_Bar__error');
504+
expect(fooBarErrors).to.have.length(1);
505+
});
471506
});
472507

473508
describe('fields ordering', () => {

0 commit comments

Comments
 (0)