---
title: "field"
description: "Define model fields and choose the type of data each field stores."
permalink: /docs/data-model/model/field/
---
# field

A `<field>` stores one value on each record of its model. Set its `name`, `label`, and `type`:

```xml
<field name="serial_number" label="Serial Number" type="text" />
```

## Field attributes

| Name | Required | Details |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
| `name` | *required* | Identifier for this field, unique per model. Used anywhere that code needs to reference the object. |
| `label` | *required* | Human-readable label for this field. Used wherever it is displayed to a user. |
| `type` | *required* | The type of this field. See the section below for the possible types. |

<span id="field-types" />

Each model field and view variable has a type that determines the values it can store. Choose from the groups below.

## Basic values

Use these types for text, numbers, true/false values, and dates.

<span id="text-values-text" />

### `text`

Stores text, from a short name to a longer paragraph. Use a subtype when you need a particular input method or validation.

Example: `"John Doe"`

#### Text subtypes

Text subtypes can change the input method shown on a mobile device and may add validation.

Add `:subtype` to the field's `type`, for example:

```xml
<field name="first_name" label="First Name" type="text:name" />
```

| Subtype | Details | Additional validation? |
| --------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| *(none)* | The default - any characters are allowed. | No |
| `text:email` | Email address. | Yes. Validates whether the entered value is a valid email address. |
| `text:address` | Street address, suburb or city. Words are automatically capitalized. | No |
| `text:name` | Person or other name. Words are automatically capitalized. | No |
| `text:url` | Web URL. | No |
| `text:paragraph` | A multi-line block of text. Renders as a paragraph rather than as a single line. | No |
| `text:number` | Only digits are allowed. | No |
| `text:signed-number` | Digits are allowed, as well as a negative sign. | Yes. Validates whether the entered value is a valid signed number. |
| `text:phone-number` | Represents a phone number. Only digits are allowed. | Yes. Validates whether the entered value is a valid phone number. |
| `text:decimal-number` | Digits are allowed, as well as a decimal point and negative sign. | No |
| `text:password` | Characters are hidden when entered. | No |

<span id="integer-integer" />

### `integer`

Stores whole numbers between −2,147,483,648 and 2,147,483,647.

Example: `100`

<span id="floating-point-value-number" />

### `number`

Stores floating-point numbers using JavaScript's IEEE 754 number format.

Example: `3.14`

<span id="boolean-boolean" />

### `boolean`

Represents a single choice from two boolean options, for example "Checked" or "Not Checked". Options are specified as two list of boolean key and label pairs, defaulting to "Yes" (true) and "No" (false).

* When accessed from JavaScript/TypeScript, the boolean key is used.
* When displaying the value to a user, the human-readable label is used.

Example options:

```xml
<option key="true">Checked</option>
<option key="false">Not Checked</option>
```

For the example, if the "Not Checked" option was selected, the value when accessed from your JavaScript/TypeScript code would be: `false`.

<span id="date-date" />

### `date`

Represents a date in the Gregorian calendar, for example "2016/10/27". Not tied to any timezone.

Example: `2016/10/27`

<span id="date-and-time-datetime" />

### `datetime`

Represents a specific date & time combination. Time is always displayed in the local timezone. For example, "2016/10/27 12:15:48" in UTC will be displayed as "2016/10/27 14:15:48" on a device configured for GMT+2.

Example: `2016/10/27 12:15:48`

## Choices

Choice fields use `<option>` elements to define the keys stored in data and the labels shown to users.

<span id="single-choice-with-text-key-single-choice" />

### `single-choice`

Represents a single choice from a list of options, for example "gender" or "province". Options are specified as a list of string key and label pairs.

* When accessed from JavaScript/TypeScript, the key is used.
* When displaying the value to a user, the human-readable label is used.

Example options:

```xml
<option key="male">Male</option>
<option key="female">Female</option>
```

For the example, if the "Female" option was selected, the value when accessed from your JavaScript/TypeScript code would be `"female"`.

<span id="single-choice-with-integer-key-single-choice-integer" />

### `single-choice-integer`

Represents a single choice from a list of options, for example "gender" or "province". Options are specified as a list of integer key and label pairs.

* When accessed from JavaScript/TypeScript, the integer key is used.
* When displaying the value to a user, the human-readable label is used.
* If the keys are not explicitly defined, they start counting from 0 and increment by one for each option.

Example options:

```xml
<option key="0">Male</option>
<option key="1">Female</option>
```

For the example, if the "Female" option was selected, the value when accessed from your JavaScript/TypeScript code would be: `1`.

<span id="multiple-choice-with-text-key-multiple-choice" />

### `multiple-choice`

Same as a `single-choice` field, but multiple values may be selected.

* When you access a multiple-choice value from JavaScript/TypeScript, the value will be an array of keys of all the selected options.

Example options:

```xml
<option key="checked-oil">Checked oil</option>
<option key="checked-tyre-pressure">Checked tyre pressure</option>
<option key="checked-water-fluid">Checked washer fluid</option>
```

For the example, if the first two options were selected, the value when accessed from your JavaScript/TypeScript code would be: `["checked-oil", "checked-tyre-pressure"]`

<span id="multiple-choice-with-integer-key-multiple-choice-integer" />

### `multiple-choice-integer`

Same as the `single-choice-integer` field, but multiple values may be selected.

* When you access a multiple-choice-integer value from JavaScript/TypeScript, the value will be an array of integer keys of all the selected options.

Example options:

```xml
<option key="0">Checked oil</option>
<option key="1">Checked type pressure</option>
<option key="2">Checked washer fluid</option>
```

For the example, if the first two options were selected, the value when accessed from your JavaScript/TypeScript code would be:\
`[0, 1]`

## Location and files

Use these types for coordinates, recorded tracks, images, and other files.

<span id="gps-location-location" />

### `location`

Represents a set of GPS coordinates. This includes:

* `latitude`
* `longitude`
* `altitude`
* `horizontal_accuracy`
* `vertical_accuracy`
* `timestamp`

<Warning title={"Limitation"}>

Capturing the `altitude` and/or `vertical_accuracy` is not supported on several platforms / devices, including Android devices. These devices will return `undefined` or `null` for these fields.

</Warning>

Example:

```javascript
{
    "latitude": -25.92593042155752,
    "longitude": 28.15002065192829,
    "altitude": 1570.0,
    "horizontal_accuracy": 10.0,
    "vertical_accuracy": null,
    "timestamp": "2013-10-17T07:25:21Z"
}
```

<span id="gps-track-track" />

### `track`

Represents a recorded GPS tracking session. Data can be displayed on a map in the App Backend or exported to GeoJSON, GPX or KML.

<span id="photo-photo" />

### `photo`

Represents a photo file, captured as a JPEG image by the mobile application.

<span id="signature-signature" />

### `signature`

Represents a signature file, captured as a 400x200px SVG file by the mobile application.

<span id="file-attachment-attachment" />

### `attachment`

Stores a file on a record or in a view variable. Must include a media attribute with one of the following types:

* `any`
* `image/jpeg`
* `image/png`
* `image/svg+xml`
* `application/pdf`
* `application/vnd.openxmlformats-officedocument.presentationml.presentation`
* `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`
* `application/vnd.openxmlformats-officedocument.wordprocessingml.document`
* `application/vnd.ms-excel`
* `application/vnd.valvelink` (Maps to `.exp` files. Introduced in Runtime version 4.90.0)
* `application/msword`
* `text/plain`
* `text/csv`
* `application/xml`
* `application/vnd.anritsu`

For example:

```xml
  <var name="file" type="attachment" media="any" />
```
