Schema reference: new features
As part of this release of Next Generation Authoring, we've added support for some additional features included in JSON schema Draft 7.
ConditionalsLink copied!
Conditionals (if/ then/ else) allow you to set the state and value of one or more properties in a schema, based on the state of another property. For example, you can use conditionals to enable or disable a property based on a user selection, or hide or show one or a group of properties.
In this section we've provided examples of some of the common uses for conditionals. See conditionals- schema examples for more.
We don't currently support all of the features specified in the JSON schema conditionals reference. In particular, wrapping multiple if/then conditions inside allOf
is not supported.
Hiding and showing propertiesLink copied!
In this example the date
field is shown or hidden based on the state of the hasDate
field.
Conditional validationLink copied!
In the example shown below, the country
property is used to determine the validation used for the addressCode
property. Different validation is used for a UK or US address.
Read only propertiesLink copied!
Read only and write only properties are now supported, as defined in the JSON Schema specification. A read only property cannot be modified.
Read only property exampleLink copied!
In the example below, the country property is set as read only. This annotation can be combined with conditionals so that the property is disabled based on the state of other properties.
Write only properties are also supported. This annotation will not affect the authoring experience, but is used as a setting for APIs.
Hidden propertiesLink copied!
You can add ui:component: "none"
to a property to hide it from the user so it's not shown on the content form. Hidden properties can be const values, or updated using the Content Management API rather than from the content form.
If a value is set for a hidden property it will be shown in the JSON output for a content item, but it will not be displayed in the content form.
Usage notesLink copied!
Note that properties with no value set will not be included in the JSON output for a content item
Be careful of listing this property as
required
. Users could end up not being able to save their content form but with no indication as to why. This could happen if developers update the content item using the Content Management API while users are updating the content item in the content form.
Content palettesLink copied!
A content palette allows you to select from an array of objects of different types, defined with the oneOf
keyword.
Each object in the array should be defined in the following format. oneOf
validation dictates that a value needs to match against one and only one schema in its array, so a const is needed to differentiate each item. "ui:component":"none"
is used so that the const value is not shown in the form.
The example below shows an image property with an image link and a string for alt text. This is one of the objects included in the array that is shown to the user as a content palette.
The full exampleList
array property shown below defines three objects: markdown text, an image link with alt text and a string used to represent a link address.
If there are 3 or fewer items defined in the array then the user selects content using buttons, while more than 3 items are shown in a menu with optional icons. See supported icons for a list of the icons that are available to use in the selection menu of content palettes.
Go to content palette, schema examples for more examples of content palettes in use.
Improved validationLink copied!
Support has now been included for the contains
keyword for use with array properties.
ContainsLink copied!
Contains allows you to specify that an array must contain at least one item that matches specified schema. This can include a number which is greater than or equal to a specified amount, a string greater than a specified length or a string equal to a value defined in a const
.
The example below shows the use of contains
to validate two array properties.
Required propertiesLink copied!
There are some differences in the way required properties are handled in Next Generation Authoring. To ensure that users will not be able to save a content item without filling in a valid value for a required property, you need to make the field required
and include some additional validation. Even if the required field is edited and left empty, it cannot be saved until it passes the specified validation.
To ensure that a string field must be entered and include a non empty value we include it in the list of required
properties and set the minLength
of the string to 1.
In the example below we have an array of strings and want to ensure that at least one item is added to the array. The tags
array is included in the list of required
properties and minItems
is set to 1. For additional validation we have also set the minLength
of each string entered to be 1.