Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update typescript definition of toIdSchema(), and passed the new idSeparator prop through to the AnyOfField and OneOfField inside of SchemaField #2743

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ should change the heading of the (upcoming) version to include a major version b
-->
# v5.0.0 (coming soon)

# v4.0.2 (upcoming)
# v4.0.3 (upcoming)

# v4.0.2

## @rjsf/core

- To improve performance, skip validating subschemas in oneOf / anyOf if formData is undefined (#2676)
- Fixed the `toIdSchema()` typescript definition to add new `idSeparator` prop along with the spelling of `idPrefix`
- Also passed the new `idSeparator` prop through to the `AnyOfField` and `OneOfField` inside of `SchemaField`
- Updated `ArrayField` in `@rjsf/core` to pass `idSeparator` and `idPrefix` through to `SchemaField`, fixing a small bug
-

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also update the PR title to note the 3 things that were changed?

# v4.0.1

Expand Down
3 changes: 2 additions & 1 deletion packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ declare module '@rjsf/core' {
id: string,
definitions: Registry['definitions'],
formData?: T,
idPredix?: string,
idPrefix?: string,
idSeparator?: string,
): IdSchema | IdSchema[];

export function toPathSchema<T = any>(
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ class ArrayField extends Component {
uiSchema={itemUiSchema}
formData={itemData}
errorSchema={itemErrorSchema}
idPrefix={this.props.idPrefix}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an optimization or a bug fix? If the latter, maybe let's add a test to ensure it doesn't regress.

Copy link
Member Author

@heath-freenome heath-freenome Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is closer to a bug fix as the props weren't being propagated all the way down... I can add a test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epicfaace Test pushed... Did you want to reapprove or shall I merge?

idSeparator={this.props.idSeparator}
idSchema={itemIdSchema}
required={this.isItemRequired(itemSchema)}
onChange={this.onChangeForIndex(index)}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ function SchemaFieldRender(props) {
formData={formData}
idPrefix={idPrefix}
idSchema={idSchema}
idSeparator={idSeparator}
onBlur={props.onBlur}
onChange={props.onChange}
onFocus={props.onFocus}
Expand All @@ -388,6 +389,7 @@ function SchemaFieldRender(props) {
formData={formData}
idPrefix={idPrefix}
idSchema={idSchema}
idSeparator={idSeparator}
onBlur={props.onBlur}
onChange={props.onChange}
onFocus={props.onFocus}
Expand Down
34 changes: 34 additions & 0 deletions packages/core/test/ArrayField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1909,4 +1909,38 @@ describe("ArrayField", () => {
expect(node.querySelector("#title-")).to.be.null;
});
});

describe("should handle nested idPrefix and idSeparator parameter", () => {
it("should render nested input widgets with the expected ids", () => {
const complexSchema = {
type: "object",
properties: {
foo: {
type: "array",
items: {
type: "object",
properties: {
bar: { type: "string" },
baz: { type: "string" },
},
},
},
},
};
const { node } = createFormComponent({
schema: complexSchema,
formData: {
foo: [{ bar: "bar1", baz: "baz1" }, { bar: "bar2", baz: "baz2" }],
},
idSeparator: "/",
idPrefix: "base",
});

const inputs = node.querySelectorAll("input[type=text]");
expect(inputs[0].id).eql("base/foo_0/bar");
expect(inputs[1].id).eql("base/foo_0/baz");
expect(inputs[2].id).eql("base/foo_1/bar");
expect(inputs[3].id).eql("base/foo_1/baz");
});
});
});