Skip to content

Commit b4b8298

Browse files
viernon1k0
authored andcommitted
Fixes array without items for custom fields (rjsf-team#590)
1 parent b21dda5 commit b4b8298

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,16 @@ export function orderProperties(properties, order) {
278278
}
279279

280280
export function isMultiSelect(schema) {
281-
return Array.isArray(schema.items.enum) && schema.uniqueItems;
281+
return schema.items
282+
? Array.isArray(schema.items.enum) && schema.uniqueItems
283+
: false;
282284
}
283285

284286
export function isFilesArray(schema, uiSchema) {
285287
return (
286-
(schema.items.type === "string" && schema.items.format === "data-url") ||
288+
(schema.items &&
289+
schema.items.type === "string" &&
290+
schema.items.format === "data-url") ||
287291
uiSchema["ui:widget"] === "files"
288292
);
289293
}

test/utils_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
dataURItoBlob,
66
deepEquals,
77
getDefaultFormState,
8+
isFilesArray,
89
isMultiSelect,
910
mergeObjects,
1011
pad,
@@ -274,6 +275,11 @@ describe("utils", () => {
274275
expect(isMultiSelect(schema)).to.be.true;
275276
});
276277

278+
it("should be false if items is undefined", () => {
279+
const schema = {};
280+
expect(isMultiSelect(schema)).to.be.false;
281+
});
282+
277283
it("should be false if uniqueItems is false", () => {
278284
const schema = { items: { enum: ["foo", "bar"] }, uniqueItems: false };
279285
expect(isMultiSelect(schema)).to.be.false;
@@ -285,6 +291,20 @@ describe("utils", () => {
285291
});
286292
});
287293

294+
describe("isFilesArray()", () => {
295+
it("should be true if items have data-url format", () => {
296+
const schema = { items: { type: "string", format: "data-url" } };
297+
const uiSchema = {};
298+
expect(isFilesArray(schema, uiSchema)).to.be.true;
299+
});
300+
301+
it("should be false if items is undefined", () => {
302+
const schema = {};
303+
const uiSchema = {};
304+
expect(isFilesArray(schema, uiSchema)).to.be.false;
305+
});
306+
});
307+
288308
describe("mergeObjects()", () => {
289309
it("should't mutate the provided objects", () => {
290310
const obj1 = { a: 1 };

0 commit comments

Comments
 (0)