-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic support for 'nullable' types (#1213)
* Basic support for 'nullable' types Modifies the implementation of `getSchemaType` so that when a property has a type of `[<any>, 'null']`, then `<any>` will be passed. This allows the library to render and validate the field correctly. For the sake of simplicity, this change does not attempt any further assumptions, coercions or transformations. References #465 * Add some test cases to `getSchemaType` spec * Add FAQ entry detailing nullable type behaviour * Add Playground example for nullable field * Tweak FAQ entry wording and fix typo Co-Authored-By: warrenseymour <warren@fountainhead.tech> * Correct example in FAQ entry Co-Authored-By: warrenseymour <warren@fountainhead.tech>
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters