Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ $ git push --tags origin master
A: The `anyOf` and `oneOf` keywords are supported, however, properties declared inside the `anyOf/oneOf` should not overlap with properties "outside" of the `anyOf/oneOf`.
There is also special cased where you can use `oneOf` in [schema dependencies](dependencies.md#schema-dependencies), If you'd like to help improve support for these keywords, see the following issues for inspiration [#329](https://github.com/mozilla-services/react-jsonschema-form/pull/329) or [#417](https://github.com/mozilla-services/react-jsonschema-form/pull/417). See also: [#52](https://github.com/mozilla-services/react-jsonschema-form/issues/52), [#151](https://github.com/mozilla-services/react-jsonschema-form/issues/151), [#171](https://github.com/mozilla-services/react-jsonschema-form/issues/171), [#200](https://github.com/mozilla-services/react-jsonschema-form/issues/200), [#282](https://github.com/mozilla-services/react-jsonschema-form/issues/282), [#302](https://github.com/mozilla-services/react-jsonschema-form/pull/302), [#330](https://github.com/mozilla-services/react-jsonschema-form/issues/330), [#430](https://github.com/mozilla-services/react-jsonschema-form/issues/430), [#522](https://github.com/mozilla-services/react-jsonschema-form/issues/522), [#538](https://github.com/mozilla-services/react-jsonschema-form/issues/538), [#551](https://github.com/mozilla-services/react-jsonschema-form/issues/551), [#552](https://github.com/mozilla-services/react-jsonschema-form/issues/552), or [#648](https://github.com/mozilla-services/react-jsonschema-form/issues/648).

In addition, 'nullabe' types are supported in a narrow sense: If a property declares a type of `["<some-type>", "null"]`, then `"some-type"` will be passed through as the type used to determine which Widget to use for rendering the field. However, the actual rendering and handling of the field is unchanged; you are free to handle this using an approach (`'ui:defaultValue': null`, for example) best-suited to your use-case.
Comment thread
wms marked this conversation as resolved.
Outdated

### Q: Will react-jsonschema-form support Material, Ant-Design, Foundation, or [some other specific widget library or frontend style]?

A: Probably not. We use Bootstrap v3 and it works fine for our needs. We would like for react-jsonschema-form to support other frameworks, we just don't want to support them ourselves. Ideally, these frontend styles could be added to react-jsonschema-form with a third-party library. If there is a technical limitation preventing this, please consider opening a PR. See also: [#91](https://github.com/mozilla-services/react-jsonschema-form/issues/91), [#99](https://github.com/mozilla-services/react-jsonschema-form/issues/99), [#125](https://github.com/mozilla-services/react-jsonschema-form/issues/125), [#237](https://github.com/mozilla-services/react-jsonschema-form/issues/237), [#287](https://github.com/mozilla-services/react-jsonschema-form/issues/287), [#299](https://github.com/mozilla-services/react-jsonschema-form/issues/299), [#440](https://github.com/mozilla-services/react-jsonschema-form/issues/440), [#461](https://github.com/mozilla-services/react-jsonschema-form/issues/461), [#546](https://github.com/mozilla-services/react-jsonschema-form/issues/546), [#555](https://github.com/mozilla-services/react-jsonschema-form/issues/555), [#626](https://github.com/mozilla-services/react-jsonschema-form/issues/626), and [#623](https://github.com/mozilla-services/react-jsonschema-form/pull/623).
Expand Down
2 changes: 2 additions & 0 deletions playground/samples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import alternatives from "./alternatives";
import propertyDependencies from "./propertyDependencies";
import schemaDependencies from "./schemaDependencies";
import additionalProperties from "./additionalProperties";
import nullable from "./nullable";

export const samples = {
Simple: simple,
Expand All @@ -44,4 +45,5 @@ export const samples = {
"Additional Properties": additionalProperties,
"Any Of": anyOf,
"One Of": oneOf,
Nullable: nullable,
};
72 changes: 72 additions & 0 deletions playground/samples/nullable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module.exports = {
schema: {
title: "A registration form (nullable)",
description: "A simple form example using nullable types",
type: "object",
required: ["firstName", "lastName"],
properties: {
firstName: {
type: "string",
title: "First name",
default: "Chuck",
},
lastName: {
type: "string",
title: "Last name",
},
age: {
type: "integer",
title: "Age",
},
bio: {
type: ["string", "null"],
title: "Bio",
},
password: {
type: "string",
title: "Password",
minLength: 3,
},
telephone: {
type: "string",
title: "Telephone",
minLength: 10,
},
},
},
uiSchema: {
firstName: {
"ui:autofocus": true,
"ui:emptyValue": "",
},
age: {
"ui:widget": "updown",
"ui:title": "Age of person",
"ui:description": "(earthian year)",
},
bio: {
"ui:widget": "textarea",
"ui:placeholder":
"Leaving this field empty will cause formData property to be `null`",
"ui:emptyValue": null,
},
password: {
"ui:widget": "password",
"ui:help": "Hint: Make it strong!",
},
date: {
"ui:widget": "alt-datetime",
},
telephone: {
"ui:options": {
inputType: "tel",
},
},
},
formData: {
lastName: "Norris",
age: 75,
bio: null,
password: "noneed",
},
};
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ export function getSchemaType(schema) {
}

if (!type && schema.enum) {
type = "string";
return "string";
}

if (type instanceof Array && type.length === 2 && type.includes("null")) {
return type.find(type => type !== "null");
}

return type;
}

Expand Down
12 changes: 12 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,18 @@ describe("utils", () => {
schema: { const: 1 },
expected: "number",
},
{
schema: { type: ["string", "null"] },
expected: "string",
},
{
schema: { type: ["null", "number"] },
expected: "number",
},
{
schema: { type: ["integer", "null"] },
expected: "integer",
},
];

it("should correctly guess the type of a schema", () => {
Expand Down