Skip to content

Commit 1c856b9

Browse files
Tonexusepicfaace
authored andcommitted
Fix omitData for top level array (rjsf-team#1406)
* Fixes omitData converting root array to object * Fixed conditional * Little bit of cleanup * Added test of getUsedFormData with top level array
1 parent df8499c commit 1c856b9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/components/Form.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ export default class Form extends Component {
139139
return formData;
140140
}
141141

142-
return _pick(formData, fields);
142+
let data = _pick(formData, fields);
143+
if (Array.isArray(formData)) {
144+
return Object.keys(data).map(key => data[key]);
145+
}
146+
147+
return data;
143148
};
144149

145150
getFieldNames = (pathSchema, formData) => {

test/Form_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,25 @@ describe("Form", () => {
866866
expect(result).eql("foo");
867867
});
868868

869+
it("should return the root level array", () => {
870+
const schema = {
871+
type: "array",
872+
items: {
873+
type: "string",
874+
},
875+
};
876+
const formData = [];
877+
const onSubmit = sandbox.spy();
878+
const { comp } = createFormComponent({
879+
schema,
880+
formData,
881+
onSubmit,
882+
});
883+
884+
const result = comp.getUsedFormData(formData, []);
885+
expect(result).eql([]);
886+
});
887+
869888
it("should call getUsedFormData with data from fields in event", () => {
870889
const schema = {
871890
type: "object",

0 commit comments

Comments
 (0)