Skip to content

Commit 6e83df1

Browse files
qingqi-spotifyQingqiShi
authored andcommitted
fix: MultiSchema getting incorrect id in arrays
1 parent 7c0d6c2 commit 6e83df1

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

packages/core/src/components/fields/SchemaField.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function SchemaFieldRender(props) {
243243
let idSchema = props.idSchema;
244244
const schema = retrieveSchema(props.schema, rootSchema, formData);
245245
idSchema = mergeObjects(
246-
toIdSchema(schema, null, rootSchema, formData, idPrefix),
246+
toIdSchema(schema, idSchema.$id, rootSchema, formData, idPrefix),
247247
idSchema
248248
);
249249
const FieldComponent = getFieldComponent(schema, uiSchema, idSchema, fields);

packages/core/test/anyOf_test.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,9 @@ describe("anyOf", () => {
810810

811811
expect(node.querySelectorAll("select")).to.have.length.of(1);
812812

813-
expect(node.querySelectorAll("input#root_foo")).to.have.length.of(1);
813+
expect(node.querySelectorAll("input#root_items_0_foo")).to.have.length.of(
814+
1
815+
);
814816
});
815817

816818
it("should not change the selected option when switching order of items for anyOf inside array items", () => {
@@ -995,8 +997,12 @@ describe("anyOf", () => {
995997
target: { value: $select.options[1].value },
996998
});
997999

998-
expect(node.querySelectorAll("input#root_foo")).to.have.length.of(1);
999-
expect(node.querySelectorAll("input#root_bar")).to.have.length.of(1);
1000+
expect(node.querySelectorAll("input#root_items_0_foo")).to.have.length.of(
1001+
1
1002+
);
1003+
expect(node.querySelectorAll("input#root_items_0_bar")).to.have.length.of(
1004+
1
1005+
);
10001006
});
10011007

10021008
it("should correctly infer the selected option based on value", () => {

packages/core/test/oneOf_test.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ describe("oneOf", () => {
494494

495495
expect($select.value).eql("1");
496496

497-
Simulate.change(node.querySelector("input#root_bar"), {
497+
Simulate.change(node.querySelector("input#root_items_bar"), {
498498
target: { value: "Lorem ipsum dolor sit amet" },
499499
});
500500

@@ -584,8 +584,12 @@ describe("oneOf", () => {
584584
target: { value: $select.options[1].value },
585585
});
586586

587-
expect(node.querySelectorAll("input#root_foo")).to.have.length.of(1);
588-
expect(node.querySelectorAll("input#root_bar")).to.have.length.of(1);
587+
expect(node.querySelectorAll("input#root_items_0_foo")).to.have.length.of(
588+
1
589+
);
590+
expect(node.querySelectorAll("input#root_items_0_bar")).to.have.length.of(
591+
1
592+
);
589593
});
590594
});
591595

0 commit comments

Comments
 (0)