Examples of content definition JSON overrides

  Written by The Jahia Team
 
Developers
   Estimated reading time:

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.

Section override examples

These examples show how to add a new section and change a section label.

Adding a new section

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.

{
  "name": "jnt:text",
  "priority": 1.0,
  "sections": [
    {
      "name": "metadata"
    }
  ]
}

Changing a section label

This JSON example changes a section label. Note that label.engineTab.publication should be present in your .properties file. You can find the file on github at META-INF/jahia-content-editor-forms/forms/jnt_news.json.

{
  "name": "jnt:news",
  "priority": 1.0,
  "sections": [
    {
      "name": "content",
      "labelKey": "label.engineTab.publication",
      "requiredPermission": "viewContentTab"
    }
  ]
}

Fieldset override examples

The following examples show how to move and hide a fieldset.

Moving 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
     }
   }
 ]
}

Hiding a fieldset

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
}

Field override examples

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.

Hiding a field

This JSON example hides the j:street field in the jmix:locationAware fieldset. You can find the file on github at META-INF/jahia-content-editor-forms/fieldsets/jmix_locationAware.json.

{
  "name": "jmix:locationAware",
  "displayName": "Location",
  "description": "",
  "dynamic": true,
  "activated": false,
  "fields": [
    {
      "name": "j:street",
      "removed": true
    }
  ]
}

Changing the order of fields in a fieldset

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
      }
    }
  ]
}

Setting a default value

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"
     }]
   }]
}

Setting a field to read only

The following JSON example sets the j:street field in the jmix:locationAware fieldset to read only. You can find the file on github at META-INF/jahia-content-editor-forms/fieldsets/jmix_locationAware.json.

{
  "name": "jmix:locationAware",
  "displayName": "Location",
  "description": "",
  "dynamic": true,
  "activated": false,
  "fields": [
    {
      "name": "j:street",
      "readOnly": true
    }
  ]
}

Adding a mandatory constraint

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
   }]
}

Adding a constraint to a field

This JSON example adds a regular expression to the mail address. You can find the file on github at META-INF/jahia-content-editor-forms/fieldsets/jnt_person.json.

{
  "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,}"
        }
      ]
    }
  ]
}

Changing constraint values

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"
       }
     ]
   }]
}

Changing a selector

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"
   }
 ]
}