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

fix: update schema to re-render when idschema changes #1493

Merged
Merged
7 changes: 1 addition & 6 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,7 @@ function SchemaFieldRender(props) {

class SchemaField extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
// if schemas are equal idSchemas will be equal as well,
// so it is not necessary to compare
return !deepEquals(
{ ...this.props, idSchema: undefined },
{ ...nextProps, idSchema: undefined }
);
return !deepEquals(this.props, nextProps);
}

render() {
Expand Down
47 changes: 47 additions & 0 deletions test/anyOf_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,53 @@ describe("anyOf", () => {
expect(selects[1].value).eql("0");
});

it("should correctly update inputs for anyOf inside array items after being moved down", () => {
const schema = {
type: "object",
properties: {
items: {
type: "array",
items: {
type: "object",
anyOf: [
{
properties: {
foo: {
type: "string",
},
},
},
{
properties: {
bar: {
type: "string",
},
},
},
],
},
},
},
};

const { node } = createFormComponent({
schema,
formData: {
items: [{}, {}],
},
});

const moveDownBtns = node.querySelectorAll(".array-item-move-down");
Simulate.click(moveDownBtns[0]);

const strInputs = node.querySelectorAll(
"fieldset .field-string input[type=text]"
);

Simulate.change(strInputs[1], { target: { value: "bar" } });
expect(strInputs[1].value).eql("bar");
});

it("should correctly render mixed types for anyOf inside array items", () => {
const schema = {
type: "object",
Expand Down