Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getFieldNames correctly defines array of primitives #3990

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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
should change the heading of the (upcoming) version to include a major version bump.

-->
# 5.15.1

## @rjsf/core

- fix `getFieldNames`. Now correctly defines an array of primitives.

# 5.15.0

## @rjsf/mui
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,11 @@ export default class Form<
const formValue = _get(formData, path);
// adds path to fieldNames if it points to a value
// or an empty object/array
if (typeof formValue !== 'object' || _isEmpty(formValue)) {
if (
typeof formValue !== 'object' ||
_isEmpty(formValue) ||
(Array.isArray(formValue) && formValue.every((val) => typeof val !== 'object'))
) {
acc.push(path);
}
});
Expand Down
5 changes: 5 additions & 0 deletions packages/core/test/Form.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,7 @@ describe('Form omitExtraData and liveOmit', () => {
extra: 'asdf',
anotherThingNested2: 0,
},
stringArray: ['scobochka'],
},
level1a: 1.23,
};
Expand All @@ -3488,6 +3489,9 @@ describe('Form omitExtraData and liveOmit', () => {
$name: 'level1.anotherThing.anotherThingNested2',
},
},
stringArray: {
$name: 'level1.stringArray',
},
},
level1a: {
$name: 'level1a',
Expand All @@ -3500,6 +3504,7 @@ describe('Form omitExtraData and liveOmit', () => {
['level1', 'anotherThing', 'anotherThingNested'],
['level1', 'anotherThing', 'anotherThingNested2'],
['level1', 'level2'],
['level1', 'stringArray'],
['level1a'],
].sort()
);
Expand Down