Skip to content

Commit

Permalink
Make getFieldNames correctly defines array of primitives (rjsf-team#3990
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Ariqun authored and Rozamo committed Dec 10, 2023
1 parent 4b67dd8 commit 78327aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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

0 comments on commit 78327aa

Please sign in to comment.