Skip to content
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 playground/samples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export const samples = {
Validation: validation,
Files: files,
Single: single,
"Custom Array": customArray
"Custom Array": customArray,
};
24 changes: 23 additions & 1 deletion playground/samples/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ module.exports = {
state: { type: "string" }
},
required: ["street_address", "city", "state"]
},
node: {
type: "object",
properties: {
name: {type: "string"},
children: {
type: "array",
items: {
$ref: "#/definitions/node"
}
}
}
}
},
type: "object",
Expand All @@ -20,11 +32,15 @@ module.exports = {
shipping_address: {
title: "Shipping address",
$ref: "#/definitions/address"
},
tree: {
title: "Recursive references",
$ref: "#/definitions/node"
}
}
},
uiSchema: {
"ui:order": ["shipping_address", "billing_address"]
"ui:order": ["shipping_address", "billing_address", "tree"]
},
formData: {
billing_address: {
Expand All @@ -36,6 +52,12 @@ module.exports = {
street_address: "221B, Baker Street",
city: "London",
state: "N/A"
},
tree: {
name: "root",
children: [
{name: "leaf"}
]
}
}
};
4 changes: 2 additions & 2 deletions src/components/widgets/TextareaWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function TextareaWidget({
}) {
const _onChange = ({target: {value}}) => {
return onChange(value === "" ? undefined : value);
};
};
return (
<textarea
id={id}
Expand All @@ -27,7 +27,7 @@ function TextareaWidget({
readOnly={readonly}
autoFocus={autofocus}
onBlur={onBlur && (event => onBlur(id, event.target.value))}
onChange={_onChange} />
onChange={_onChange}/>
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ export function toIdSchema(schema, id, definitions) {
};
if ("$ref" in schema) {
const _schema = retrieveSchema(schema, definitions);
return toIdSchema(_schema, id, definitions);
return toIdSchema(_schema, id, definitions, schema.$ref);
}
if ("items" in schema) {
if ("items" in schema && !schema.items.$ref) {
return toIdSchema(schema.items, id, definitions);
}
if (schema.type !== "object") {
Expand Down
30 changes: 30 additions & 0 deletions test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,36 @@ describe("Form", () => {
.eql("hello");
});

it("should recursively handles referenced definitions", () => {
const schema = {
$ref: "#/definitions/node",
definitions: {
node: {
type: "object",
properties: {
name: {type: "string"},
children: {
type: "array",
items: {
$ref: "#/definitions/node"
}
}
}
}
}
};

const {node} = createFormComponent({schema});

expect(node.querySelector("#root_children_0_name"))
.to.not.exists;

Simulate.click(node.querySelector(".array-item-add button"));

expect(node.querySelector("#root_children_0_name"))
.to.exists;
});

it("should priorize definition over schema type property", () => {
// Refs bug #140
const schema = {
Expand Down