Skip to content
New issue

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

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

Already on GitHub? # to your account

Ensure defaults are passed along for multiselect arrays when minItems… #1264

Merged
merged 3 commits into from
Jun 3, 2019
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
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function computeDefaults(schema, parentDefaults, definitions = {}) {
return defaultEntries.concat(fillerEntries);
}
} else {
return [];
return defaults ? defaults : [];
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,27 @@ describe("utils", () => {
array: ["foo"],
});
});

it("defaults passed along for multiselect arrays when minItems is present", () => {
const schema = {
type: "object",
properties: {
array: {
type: "array",
minItems: 1,
uniqueItems: true,
default: ["foo", "qux"],
items: {
type: "string",
enum: ["foo", "bar", "fuzz", "qux"],
},
},
},
};
expect(getDefaultFormState(schema, {})).eql({
array: ["foo", "qux"],
});
});
});
});

Expand Down