# @keystone-alpha/fields

> KeystoneJS Field Types including Text, Password, DateTime, Integer, and more.

Latest version **15.0.0** (published 2019-10-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @keystone-alpha/fields
pnpm add @keystone-alpha/fields
yarn add @keystone-alpha/fields
bun add @keystone-alpha/fields
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 15.0.0 |
| Published | 2019-10-23 |
| First published | 2019-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8.4.0 |
| Dependencies | 60 |
| Unpacked size | 947 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Author | The KeystoneJS Development Team |
| Maintainers | dominikwilkowski, jedwatson, jesstelford, mitchellhamilton, molomby, timl |

## Links

- npm: https://www.npmjs.com/package/@keystone-alpha/fields
- npm.io page: https://npm.io/package/@keystone-alpha/fields

## Dependencies (60)

- [cuid](https://npm.io/package/cuid.md) ^2.1.6
- [luxon](https://npm.io/package/luxon.md) ^1.11.4
- [react](https://npm.io/package/react.md) ^16.8.6
- [slate](https://npm.io/package/slate.md) ^0.47.4
- [bcrypt](https://npm.io/package/bcrypt.md) ^3.0.6
- [graphql](https://npm.io/package/graphql.md) ^14.4.2
- [date-fns](https://npm.io/package/date-fns.md) ^1.30.1
- [mongoose](https://npm.io/package/mongoose.md) ^5.6.5
- [p-settle](https://npm.io/package/p-settle.md) ^3.1.0
- [immutable](https://npm.io/package/immutable.md) ^3.8.1
- [pluralize](https://npm.io/package/pluralize.md) ^7.0.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.8.6
- [inflection](https://npm.io/package/inflection.md) ^1.12.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.3.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.10.1
- [react-color](https://npm.io/package/react-color.md) ^2.17.0
- [slate-react](https://npm.io/package/slate-react.md) ^0.22.4
- [unsplash-js](https://npm.io/package/unsplash-js.md) ^5.0.0
- [query-string](https://npm.io/package/query-string.md) ^6.8.1
- [react-apollo](https://npm.io/package/react-apollo.md) 2.4.0
- [react-popper](https://npm.io/package/react-popper.md) ^1.3.3
- [react-select](https://npm.io/package/react-select.md) ^3.0.4
- [@emotion/core](https://npm.io/package/@emotion/core.md) ^10.0.14
- [apollo-errors](https://npm.io/package/apollo-errors.md) ^1.9.0
- [@arch-ui/alert](https://npm.io/package/@arch-ui/alert.md) ^0.0.7
- [@arch-ui/icons](https://npm.io/package/@arch-ui/icons.md) ^0.0.5
- [@arch-ui/input](https://npm.io/package/@arch-ui/input.md) ^0.1.0
- [@arch-ui/theme](https://npm.io/package/@arch-ui/theme.md) ^0.0.5
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.3
- [dumb-passwords](https://npm.io/package/dumb-passwords.md) ^0.2.1
- [lodash.groupby](https://npm.io/package/lodash.groupby.md) ^4.6.0
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [@arch-ui/button](https://npm.io/package/@arch-ui/button.md) ^0.0.9
- [@arch-ui/drawer](https://npm.io/package/@arch-ui/drawer.md) ^0.0.10
- [@arch-ui/fields](https://npm.io/package/@arch-ui/fields.md) ^2.0.1
- [@arch-ui/layout](https://npm.io/package/@arch-ui/layout.md) ^0.2.4
- [@arch-ui/popout](https://npm.io/package/@arch-ui/popout.md) ^0.0.8
- [@arch-ui/select](https://npm.io/package/@arch-ui/select.md) ^0.1.0
- [@arch-ui/filters](https://npm.io/package/@arch-ui/filters.md) ^0.0.11
- [@arch-ui/loading](https://npm.io/package/@arch-ui/loading.md) ^0.0.8
- [@arch-ui/lozenge](https://npm.io/package/@arch-ui/lozenge.md) ^0.0.7
- [@arch-ui/options](https://npm.io/package/@arch-ui/options.md) ^0.0.9
- [@arch-ui/tooltip](https://npm.io/package/@arch-ui/tooltip.md) ^0.1.2
- [image-extensions](https://npm.io/package/image-extensions.md) ^1.1.0
- [@arch-ui/controls](https://npm.io/package/@arch-ui/controls.md) ^0.0.10
- [google-maps-react](https://npm.io/package/google-maps-react.md) ^2.0.2
- [@arch-ui/day-picker](https://npm.io/package/@arch-ui/day-picker.md) ^0.0.13
- [@arch-ui/typography](https://npm.io/package/@arch-ui/typography.md) ^0.0.8
- [react-popper-tooltip](https://npm.io/package/react-popper-tooltip.md) ^2.8.1
- [@keystone-alpha/utils](https://npm.io/package/@keystone-alpha/utils.md) ^3.2.0
- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) ^0.6.0
- [intersection-observer](https://npm.io/package/intersection-observer.md) ^0.5.1
- [react-toast-notifications](https://npm.io/package/react-toast-notifications.md) ^2.2.4
- [slate-drop-or-paste-images](https://npm.io/package/slate-drop-or-paste-images.md) ^0.9.1
- [@keystone-alpha/adapter-knex](https://npm.io/package/@keystone-alpha/adapter-knex.md) ^6.0.2
- [@keystone-alpha/field-content](https://npm.io/package/@keystone-alpha/field-content.md) ^3.1.4
- [@keystone-alpha/access-control](https://npm.io/package/@keystone-alpha/access-control.md) ^3.0.0
- [@keystone-alpha/adapter-mongoose](https://npm.io/package/@keystone-alpha/adapter-mongoose.md) ^6.0.1
- [@keystone-alpha/build-field-types](https://npm.io/package/@keystone-alpha/build-field-types.md) ^1.0.6

## Recent versions

- 15.0.0 (latest) — 2019-10-23
- 14.0.0 — 2019-10-15
- 13.1.0 — 2019-10-09
- 13.0.0 — 2019-10-02
- 12.3.0 — 2019-09-27
- 12.2.1 — 2019-09-18
- 12.2.0 — 2019-09-18
- 12.1.0 — 2019-09-17
- 12.0.0 — 2019-09-17
- 11.0.0 — 2019-09-12
- 10.7.2 — 2019-09-03
- 10.6.2 — 2019-08-27
- 10.6.1 — 2019-08-23
- 10.6.0 — 2019-08-23
- 10.5.0 — 2019-08-23
- … 27 more at https://npm.io/package/@keystone-alpha/fields/versions

## README

<!--[meta]
section: api
title: Fields
order: 3
[meta]-->

# Fields

KeystoneJS contains a set of primitive fields types that can be imported from `@keystone-alpha/fields`. These include:

- [CalendarDay](keystone-alpha/fields/src/types/calendar-day)
- [Checkbox](keystone-alpha/fields/src/types/checkbox)
- [CloudinaryImage](keystone-alpha/fields/src/types/cloudinary-image)
- [Color](keystone-alpha/fields/src/types/color)
- [Content](/keystone-alpha/field-content)
- [DateTime](keystone-alpha/fields/src/types/date-time)
- [Decimal](keystone-alpha/fields/src/types/decimal)
- [File](keystone-alpha/fields/src/types/file)
- [Float](keystone-alpha/fields/src/types/float)
- [Integer](keystone-alpha/fields/src/types/integer)
- [Location](keystone-alpha/fields/src/types/location)
- [OEmbed](keystone-alpha/fields/src/types/o-embed)
- [Password](keystone-alpha/fields/src/types/password)
- [Relationship](keystone-alpha/fields/src/types/relationship)
- [Select](keystone-alpha/fields/src/types/select)
- [Slug](keystone-alpha/fields/src/types/slug)
- [Text](keystone-alpha/fields/src/types/text)
- [Unsplash](keystone-alpha/fields/src/types/unsplash)
- [Url](keystone-alpha/fields/src/types/url)
- [Uuid](keystone-alpha/fields/src/types/uuid)

In addition to these are some other complex types that have their own package such as `Markdown` and `Wysiwyg`.

Need more? See our guide on [Custom field types](/guides/custom-field-types/).

## Usage

Fields definitions are provided when creating a list. Field definitions should be an object where the key is the field name and the value is an object containing the fields config:

```javascript
keystone.createList('Post', {
  fields: {
    title: { type: Text },
  },
});
```

## Config

Fields share some standard configuration options.

| Option         | Type                                | Default     | Description                                                       |
| -------------- | ----------------------------------- | ----------- | ----------------------------------------------------------------- |
| `type`         | `FieldType`                         | (required)  |                                                                   |
| `schemaDoc`    | `Boolean`                           | `false`     | A description for the field used in the AdminUI.                  |
| `defaultValue` | `Boolean` \| `Function`             | `undefined` | A default value of the field.                                     |
| `isUnique`     | `Boolean`                           | `false`     | Whether or not the field should be unique.                        |
| `isRequired`   | `Boolean`                           | `false`     | Whether or not the field should be mandatory.                     |
| `access`       | `Boolean` \| `Function` \| `Object` | `true`      | See: (Access control)[/guides/access-control] options for fields. |
| `label`        | `String`                            |             | Label for the field.                                              |

_Note_: Many field types have additional config options. See the documentation for individual field types for more detail.

### `type`

A valid `Keystone` field type.

### `label`

Sets the label for the field in the AdminUI

### `schemaDoc`

A description of the field used in the AdminUI.

### `defaultValue`

Sets the value when no data is provided.

#### Usage

```javascript
keystone.createList('Post', {
  fields: {
    title: {
      type: Text,
      defaultValue: ({ existingItem, context, originalInput, actions }) => {
        /**/
      },
    },
    description: { type: Text, defaultValue: 'Lorem ipsum...' },
  },
});
```

For a 'nullable' field, set `defaultValue: null`.

The `defaultValue` can be a `String` or `Function`. Functions should returns the value, or a Promise for the value.

### `isUnique`

Specifies whether the value should be unique or not. Will return an error is a user tries to create a field with a non-unique value.

### `isRequired`

Specifies whether the field is required or not. Will return an error if mutations do not contain data.

### `access`

[Access control](https://keystonejs.com/guides/access-control) options for fields.

Options for `create`, `read`, `update` and `delete` - can be a function or Boolean. See the [access control API documentation](https://keystonejs.com/api/access-control) for more details.

_Note_: Field level access control does not accept graphQL where clauses.

### `cacheHint`

[HTTP cache hint](https://keystonejs.com/api/create-list#cacheHint) for field.

Only static hints are supported for fields.

---
_Source: https://npm.io/package/@keystone-alpha/fields · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
