Index
Edit

Array

An ordered list of data. The of property specifies which value types the array may hold.

Use options.layout and options.sortable to control list behavior. options.layout: 'tags' will only work if the array contains strings and only strings.

Properties

  • ofarray - Defines which types are allowed as members of the array.
  • optionsobject - Extra type options. See below.
  • sortableboolean - Default true

Example: Array of Strings

{
  title: 'Roles',
  name: 'roles',
  type: 'array',
  of: [{type: 'string'}]
}

Options

  • layout: tags if specified and if the array only contains strings, a special input widget specialized for editing a list of tags will be used
  • editModal: fold | popover| fullscreen

Example: Array which may contain crew members or cast members

Both crewMember and castMember are custom types defined in our schema. In this example we want an array of employees that may may contain crew members or cast members. The resulting array will end up containing inline instances of the actual objects. Note that in a real world example, you may want this to be references to existing cast members or crew members.

{
  title: 'Employees',
  name: 'employees',
  type: 'array',
  of: [{type: 'crewMember'}, {type: 'castMember'}]
}

Example data

Why the _key?

When adding an data of an object type to an array, each item gets assigned a persistent and unique _key-property. This is to ensure that each item can be addressed uniquely in a realtime setting, where one user may edit one array item, while another user reorders the same array at the same time.

Limitations

Arrays that holds values of primitive types (e.g. strings or numbers) can not be adressed uniquely by a key in a realtime setting, where one user may edit an array item, while at the same time another user reorders the same array. As a consequence, when defining an array of primitive values, the content studio will switch to a simpler array input widget for editing. This input widget will not be able to handle object types, so for this reason it is not possible to define arrays that contains both object types and primitive types. If you should ever need an array that contains both strings and objects (e.g. movie) objects, you should instead wrap the string values in an object type (e.g. defined in-place), and give it a property that holds the string value.

This will not work:

{
  type: 'array',
  of: [
    {
type: 'actor',
title: 'Actor' }, {
type: 'string', /* Will not work! */
title: 'Actor name' } ] }

This is OK:

{
  type: 'array',
  of: [
    {
      type: 'actor',
      title: 'Actor'
    },
    {
      type: 'object',
      title: 'Actor name',
      fields: [
        {
          name: 'value',
          type: 'string',
          title: 'Name'
        } 
      ]
    }
  ]
}

Previous: BooleanNext: Block Text