Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Fixes rjsf-team#156: Propagate resolved schema definitions to field c…
Browse files Browse the repository at this point in the history
…omponents. (rjsf-team#157)
  • Loading branch information
n1k0 committed Apr 22, 2016
1 parent c94491b commit 497620f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
23 changes: 13 additions & 10 deletions playground/samples/large.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ function largeEnum(n) {

module.exports = {
schema: {
definitions: {
largeEnum: {type: "string", enum: largeEnum(100)}
},
title: "A rather large form",
type: "object",
properties: {
string: {
type: "string",
title: "Some string",
},
choice1: {type: "string", enum: largeEnum(100)},
choice2: {type: "string", enum: largeEnum(100)},
choice3: {type: "string", enum: largeEnum(100)},
choice4: {type: "string", enum: largeEnum(100)},
choice5: {type: "string", enum: largeEnum(100)},
choice6: {type: "string", enum: largeEnum(100)},
choice7: {type: "string", enum: largeEnum(100)},
choice8: {type: "string", enum: largeEnum(100)},
choice9: {type: "string", enum: largeEnum(100)},
choice10: {type: "string", enum: largeEnum(100)},
choice1: {$ref: "#/definitions/largeEnum"},
choice2: {$ref: "#/definitions/largeEnum"},
choice3: {$ref: "#/definitions/largeEnum"},
choice4: {$ref: "#/definitions/largeEnum"},
choice5: {$ref: "#/definitions/largeEnum"},
choice6: {$ref: "#/definitions/largeEnum"},
choice7: {$ref: "#/definitions/largeEnum"},
choice8: {$ref: "#/definitions/largeEnum"},
choice9: {$ref: "#/definitions/largeEnum"},
choice10: {$ref: "#/definitions/largeEnum"},
}
},
uiSchema: {},
Expand Down
4 changes: 2 additions & 2 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function SchemaField(props) {

return (
<Wrapper
label={schema.title || name}
label={props.schema.title || schema.title || name}
errorSchema={errorSchema}
hidden={uiSchema["ui:widget"] === "hidden"}
help={uiSchema["ui:help"]}
Expand All @@ -141,7 +141,7 @@ function SchemaField(props) {
displayLabel={displayLabel}
id={idSchema.id}
classNames={uiSchema.classNames}>
<FieldComponent {...props} />
<FieldComponent {...props} schema={schema} />
</Wrapper>
);
}
Expand Down
17 changes: 17 additions & 0 deletions test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ describe("Form", () => {
expect(node.querySelectorAll("input[type=text]"))
.to.have.length.of(2);
});

it("should propagate and handle a resolved schema definition", () => {
const schema = {
definitions: {
enumDef: {type: "string", enum: ["a", "b"]}
},
type: "object",
properties: {
name: {$ref: "#/definitions/enumDef"}
},
};

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

expect(node.querySelectorAll("option"))
.to.have.length.of(2);
});
});

describe("Defaults array items default propagation", () => {
Expand Down

0 comments on commit 497620f

Please sign in to comment.