# Field

**Kind:** Class

Model class representing a field in a table.

```js
import {useBase} from '@airtable/blocks/interface/ui';

function App() {
    const base = useBase();
    const table = base.getTableByName('Table 1');
    const field = table.getFieldByName('Name');
    console.log('The type of this field is', field.type);
}
```

## Properties

### `config`

Type: `FieldConfig`

The type and options of the field to make type narrowing `FieldOptions` easier.
See `FieldType` for more information on the options for each field type.

```js
const fieldConfig = field.config;
if (fieldConfig.type === FieldType.SINGLE_SELECT) {
    return fieldConfig.options.choices;
} else if (fieldConfig.type === FieldType.MULTIPLE_LOOKUP_VALUES && fieldConfig.options.isValid) {
    if (fieldConfig.options.result.type === FieldType.SINGLE_SELECT) {
        return fieldConfig.options.result.options.choices;
    }
}
return DEFAULT_CHOICES;
```

### `description`

Type: `string | null`

The description of the field, if it has one. Can be watched.

```js
console.log(myField.description);
// => 'This is my field'
```

### `id`

Type: `string`

The ID for this model.

### `isComputed`

Type: `boolean`

`true` if this field is computed, `false` otherwise. A field is
"computed" if it's value is not set by user input (e.g. autoNumber, formula,
etc.). Can be watched

```js
console.log(mySingleLineTextField.isComputed);
// => false
console.log(myAutoNumberField.isComputed);
// => true
```

### `isDeleted`

Type: `boolean`

`true` if the model has been deleted, and `false` otherwise.

In general, it's best to avoid keeping a reference to an object past the
current event loop, since it may be deleted and trying to access any data
of a deleted object (other than its ID) will throw. But if you keep a
reference, you can use `isDeleted` to check that it's safe to access the
model's data.

### `isPrimaryField`

Type: `boolean`

`true` if this field is its parent table's primary field, `false` otherwise.
Should never change because the primary field of a table cannot change.

### `name`

Type: `string`

The name of the field. Can be watched.

```js
console.log(myField.name);
// => 'Name'
```

### `options`

Type: `FieldOptions | null`

The configuration options of the field. The structure of the field's
options depend on the field's type. `null` if the field has no options.
See `FieldType` for more information on the options for each field
type. Can be watched.

```js
import {FieldType} from '@airtable/blocks/interface/models';

if (myField.type === FieldType.CURRENCY) {
    console.log(myField.options.symbol);
    // => '$'
}
```

### `type`

Type: `FieldType`

The type of the field. Can be watched.

```js
console.log(myField.type);
// => 'singleLineText'
```

## Methods

### `convertStringToCellValue(string)`

Attempt to parse a given string and return a valid cell value for the field's current config.
Returns `null` if unable to parse the given string.

**Parameters:**
- `string` (`string`) — The string to parse.

**Returns:** `unknown`

```js
const inputString = '42';
const cellValue = myNumberField.convertStringToCellValue(inputString);
console.log(cellValue === 42);
// => true
```

### `toString()`

A string representation of the model for use in debugging.

**Returns:** `string`

### `unwatch(keys, callback, context?)`

Unwatch keys watched with `.watch`.

Should be called with the same arguments given to `.watch`.

Returns the array of keys that were unwatched.

**Parameters:**
- `keys` (`WatchableFieldKey | ReadonlyArray<WatchableFieldKey>`) — the keys to unwatch
- `callback` (`object`) — the function passed to `.watch` for these keys
- `context?` (`FlowAnyObject | null`) — the context that was passed to `.watch` for this `callback`

**Returns:** `Array<WatchableFieldKey>`

### `watch(keys, callback, context?)`

Get notified of changes to the model.

Every call to `.watch` should have a matching call to `.unwatch`.

Returns the array of keys that were watched.

**Parameters:**
- `keys` (`WatchableFieldKey | ReadonlyArray<WatchableFieldKey>`) — the keys to watch
- `callback` (`object`) — a function to call when those keys change
- `context?` (`FlowAnyObject | null`) — an optional context for `this` in `callback`.

**Returns:** `Array<WatchableFieldKey>`
