This topic provides examples of content definition JSON overrides that you can use to customize your Content Editor forms. The examples show how to customize sections, fields, and fieldsets.
These examples show how to add a new section and change a section label.
The following JSON example adds fieldset metadata to the jnt:text
form. You can find the file on github at src/test/resources/META-INF/jahia-content-editor-forms/forms/jnt_text.json
.
{
"nodeType": "jnt:text",
"priority": 1.0,
"sections": [
{
"name": "metadata"
}
]
}
This JSON example changes a section label. Note that label.engineTab.publication
should be present in your .properties
file.
{
"nodeType": "jnt:news",
"priority": 1.0,
"sections": [
{
"name": "content",
"labelKey": "label.engineTab.publication",
"requiredPermission": "viewContentTab"
}
]
}
The following examples show how to move and hide a fieldset.
This override moves the title fieldset to the top of the form.
{
"name": "mix:title",
"priority": 1.0,
"rank": -1.0
}
This override moves tags in the classification section.
{
"name": "jmix:tagged",
"priority": 1.0,
"fields": [
{
"name": "j:tagList",
"target": {
"sectionName": "classification",
"rank": 1
}
}
]
}
This JSON example hides the jmix:categorized
fieldset. You can find this file on github at src/test/resources/META-INF/jahia-content-editor-forms/fieldsets/jmix_categorized.json
.
{
"name": "jmix:categorized",
"priority": 1.0,
"removed": true
}
The following examples show how to hide a field, change the order of fields, add a mandatory constraint, set a default value, and make a field read only. They also show how to add a constraint to a field, add and change constraint values, and change a selector.
This JSON example hides the j:street
field in the jmix:locationAware
fieldset.
{
"name": "jmix:locationAware",
"displayName": "Location",
"description": "",
"dynamic": true,
"activated": false,
"fields": [
{
"name": "j:street",
"removed": true
}
]
}
The following JSON example changes the order of fields in a fieldset based on their rank
value. Note that you must add the rank
property in the definition of the form. You can find the file on github at META-INF/jahia-content-editor-forms/fieldsets/jmix_tagged.json
.
{
"name": "jmix:tagged",
"priority": 1.0,
"fields": [
{
"name": "j:tagList",
"target": {
"rank": 1
}
}
]
}
You can set a default value for a field by setting the defaultValues array property of the field element to a couple of type or value elements. Multiple default values can be set for a multiple property. Note that default values provided by override are not localized.
The following override sets a default value for intro of an article type.
{
"name": "jnt:article",
"priority": 1.1,
"fields": [
{
"name": "intro",
"defaultValues": [{
"type": "STRING",
"value": "article value"
}]
}]
}
The following JSON example sets the j:street
field in the jmix:locationAware
fieldset to read only.
{
"name": "jmix:locationAware",
"displayName": "Location",
"description": "",
"dynamic": true,
"activated": false,
"fields": [
{
"name": "j:street",
"readOnly": true
}
]
}
You can add a mandatory constraint by setting the mandatory property of the field element to true. The following override makes the description mandatory.
{
"name": "jmix:description",
"priority": 1.1,
"fields": [
{
"name": "jcr:description",
"mandatory": true
}]
}
This JSON example adds a regular expression to the mail address.
{
"name": "jnt:person",
"displayName": "Person portrait",
"description": "",
"dynamic": true,
"activated": false,
"fields": [
{
"name": "email",
"valueConstraints": [
{
"value": {
"type": "String",
"value": "^$|[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,}"
},
"displayValue": "^$|[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,}"
}
]
}
]
}
With the previous definition, an error will be displayed like on the following screenshot if the email field does not match the regular expression defined in the value constraint.
The following override changes constraint values.
{
"name": "jmix:description",
"priority": 1.1,
"fields": [
{
"name": "jcr:description",
"mandatory": false,
"target": {
"sectionName": "metadata",
"rank": 0.0
},
"valueConstraints": [
{
"value": {
"type": "String",
"value": "^[A-Z]+.*"
},
"displayValue": "Must start with a capitalized letter"
}
]
}]
}
You can change a selector by setting the selectorType property of the field element to chosen selector value. Find more about custom selectors at Creating custom selector types for Content Editor.
This override sets a custom selector for markDownText of markdownField type.
{
"name": "eent:markdownField",
"fields": [
{
"name": "markDownText",
"selectorType": "Markdown"
}
]
}