# Field, Field set, Field section

The Interaction Cloud operates with the following data structures:

|               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Field         | <p>Field describes a piece of data of a specific type,</p><p>how to collect it and how to send it to the</p><p>client App. For example a field of type <code>colour</code> provides the Creator with a colour picker UI and produces a colour specification</p><p>string to the client App.</p>                                                                                                                                                                   |
| Field set     | <p>Field set is an ordered list of references to fields.</p><p>Field sets link Project settings, Events settings and so on with fields.</p><p>A number of additional settings are available allowing field</p><p>customisation for different contexts. For example a field</p><p>"description" can be referenced in one field set as mandatory</p><p>to be used for Project settings and in another field set as</p><p>optional to be used in Event settings.</p> |
| Field section | <p>Field section is a named field set. It is used to represent the sets of</p><p>fields to the Creator divided into sections.</p>                                                                                                                                                                                                                                                                                                                                 |

Below is a diagram showing different data structures relationships:

![](https://content.gitbook.com/content/q9pQqNk9IovpAN9EXqbX/blobs/H9WY4D8jlhdpcq42cuL0/image.png)

* Project and Event settings link to fields via field sections.
* Elements also may have custom fields and these work in the same way as Project and Event settings - via field sections.
* Poll-like Elements describe what a Poll question and answer options are made of in terms of field sets.
* `Collection` type fields use a field set to describe a collection item.

## Fields

Fields can be used with Elements, Events or Projects. Each field can be described using the following attributes:

| Name        | Description                                                                                                                     | Mandatory | Default |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------- | --------- | ------- |
| key         | Data is passed to client application under this key. This must be unique for the Project.                                       | yes       |         |
| type        | Defines what UI is used to collect data by the Creator.                                                                         | yes       |         |
| localisable | Allows to define values of the field using multiple languages. Only supported for `freetext`, `wysiwyg`, `image`, `file` types. | no        | `false` |
| default     | The default value for the field.                                                                                                | no        |         |

```javascript
[
  {
    "key": "podium",
    "type": "external",
    "source": {
      "url": "http://example.com/feeds/podium.json",
      "method": "get"
    },
    "select": {
      "mode": "list",
      "min": 2,
      "max": 2,
      "filtering": "off"
    }
  },
  {
    "key": "strap",
    "type": "freetext",
    "default": "Default text",
    "localisable": false
  },
  {
    "key": "availbale",
    "type": "boolean",
    "default": true
  }
]
```

## Field set

A field set is an array of fields. Each field refers to a Field declaration in a fields feed. Each Field can customise the Field declaration it references by specifying extra parameters like "mandatory" flag or default value.

Field sets can be used to describe Project, Event, Element fields.

| Name           | Description                                                                                                                                                                                                                                                                                                                                                                                                                           | Mandatory | Default |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------- |
| label          | A name for corresponding UI element.                                                                                                                                                                                                                                                                                                                                                                                                  | yes       |         |
| key            | <p>Used as property name to communicate this data to the client.</p><p>It's also used to link to the field declaration in fields feed.</p>                                                                                                                                                                                                                                                                                            | yes       |         |
| field          | If `field` property is present, then its value is used as a reference to the field declaration instead of `key`. It allows reusing a field declaration in different field sets.                                                                                                                                                                                                                                                       | no        |         |
| description    | Text description of the Field to display in UI. See details [here](#description).                                                                                                                                                                                                                                                                                                                                                     | no        |         |
| mandatory      | <p>An attribute configuring if it is mandatory to fill data before saving (and publishing in case of an Element) content with which this field is associated. </p><p>Applied only to the default locale.</p><p></p><p>Posible values:</p><ul><li><code>true</code>/<code>false</code></li><li>string - for <a href="#mandatory-groups">mandatory group</a></li><li><a href="expressions-beta">boolean expression (beta)</a></li></ul> | no        | `false` |
| default        | The default value for the field. This value overrides default in the field declaration.                                                                                                                                                                                                                                                                                                                                               | no        |         |
| public         | Controls whether the field value will be exposed to the client App.                                                                                                                                                                                                                                                                                                                                                                   | no        | `true`  |
| cloneable      | <p>A boolean flag which determines whether the value of the field is copied at the time of exporting or cloning operations.</p><p>See details <a href="#cloneable">here</a>.</p>                                                                                                                                                                                                                                                      | no        | `true`  |
| visible (beta) | <p>Allows to specify if a field is visible in UI. Invisible fields still can be accessed via API, and they are available to the client app.<br></p><p>Posible values:</p><ul><li><code>true</code>/<code>false</code></li><li><a href="expressions-beta">boolean expression</a></li></ul>                                                                                                                                             | no        | `true`  |
| items\_number  | Min/max number of `collection` items. Allowed only for fields with `collection` type.                                                                                                                                                                                                                                                                                                                                                 | no        |         |

### Description

The `description` property allows to setup a textual representation of the field. This provides a way to explain the field's purpose and enhance user experience by offering clear and comprehensive descriptions directly in the user interface.

It supports a subset of HTML tags for formatting the text. Supported tags are:

* `<b>`: Bold text
* `<i>`: Italic text
* `<strong>`: Strong emphasis
* `<em>`: Emphasis

For example, the following code defines a bold text and an italic text.

```json
"description": "<b>This is bold text</b> and <i>this is italic text</i>"
```

#### Adding Links

The `description` property also facilitates adding clickable links to the field description by supporting the `<a>` HTML tag with the `href` attribute.

For instance,

```json
"description": "For more details, visit <a href='https://www.example.com'>here</a>"
```

On rendering, this will create a hyperlink in the field description, which on click, opens the specified web page in a new browser tab/window.

### Cloneable

The `cloneable` is a boolean flag, with default value set to `true`.

Cloneable fields have their current value copied during any of these operations:

* Event export
* App settings export
* Event cloning
* Event template creation from an event
* Element cloning

In some cases the value is specific to event/element and must not be cloned. For such fields `cloneable` should be set to `false`. In this case new field is set to default value if such value is specified or empty value otherwise, not the original value.

The following operations are not affected by `cloneable` flag. They treat all fields as cloneable.

* Event import&#x20;
* App settings import
* Event creation from a template

Updates of `cloneable` attribute via App Spec update do not affect the current values but only future operations.

`cloneable` attribute is taken from the destination App Spec, not source one. For example, given the source App Spec has `cloneable` set to `true` and destination one has it set to `false` the value will not be cloned. This is applicable only to Event and Element cloning, but not to import/export operations.

```javascript
[
   {
       "label": "Podium",
       "key": "podium",
       "mandatory": true,
       "description": "Podium field description"
   },
   {
       "label": "Strap line",
       "key": "strap",
       "mandatory": false,
       "default": "Hello",
       "cloneable": false,
       "description": "Strap line field description"
   },
   {
       "label": "Rating",
       "key": "rating",
       "mandatory": "group1",
       "public": false,
       "description": "Rating field description"
   },
   {
       "label": "Competition",
       "description": "Competition is a ...",
       "key": "competition_id",
       "mandatory": "group1",
       "field": "comp_id",
       "description": "Competition field description"
   },
   {
       "label": "Slides",
       "key": "carousel",
       "items_number": { "min": 1, "max": 2 },
       "description": "Slides field description"
   }
]
```

### Mandatory groups

When the value of the `mandatory` property is a string, this field belongs to the correspondingly named mandatory group. At least one field of the mandatory group must be filled with data in order to save data:

```javascript
[
   {
       "label": "Question text",
       "key": "question_text",
       "mandatory": "question_content",
       "field": "text"
   },
   {
       "label": "Question image",
       "key": "question_image",
       "mandatory": "question_content",
       "field": "img"
   }
]
```

## Field section

Field section is a named field set.

| Name       | Description                                                             |
| ---------- | ----------------------------------------------------------------------- |
| name       | Used to present a set of fields as a group of related fields in the UI. |
| properties | Describes the field set.                                                |

```javascript
{
  "sections": [
    {
      "name": "Appearance",
      "description": "Appearance section is a ...",
      "properties": [
        {
          "label": "Background color",
          "key": "appearance_background_color",
          "mandatory": false,
          "description": "Background color is a ..."
        }
      ],
      "subsections": [
        {
          "name": "Foreground",
          "description": "Foreground section is a ...",
          "properties": [
            {
              "label": "Foreground color",
              "key": "appearance_foreground_color",
              "mandatory": false,
              "description": "Foreground color is a ..."
            }
          ]
        }
      ]
    }
  ]
}
```
