Skip to content

Commit

Permalink
Fix omitData for top level array (#1406)
Browse files Browse the repository at this point in the history
* Fixes omitData converting root array to object

* Fixed conditional

* Little bit of cleanup

* Added test of getUsedFormData with top level array
  • Loading branch information
Tonexus authored and epicfaace committed Aug 18, 2019
1 parent df8499c commit 1c856b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ export default class Form extends Component {
return formData;
}

return _pick(formData, fields);
let data = _pick(formData, fields);
if (Array.isArray(formData)) {
return Object.keys(data).map(key => data[key]);
}

return data;
};

getFieldNames = (pathSchema, formData) => {
Expand Down
19 changes: 19 additions & 0 deletions test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,25 @@ describe("Form", () => {
expect(result).eql("foo");
});

it("should return the root level array", () => {
const schema = {
type: "array",
items: {
type: "string",
},
};
const formData = [];
const onSubmit = sandbox.spy();
const { comp } = createFormComponent({
schema,
formData,
onSubmit,
});

const result = comp.getUsedFormData(formData, []);
expect(result).eql([]);
});

it("should call getUsedFormData with data from fields in event", () => {
const schema = {
type: "object",
Expand Down

0 comments on commit 1c856b9

Please sign in to comment.