> ## Documentation Index
> Fetch the complete documentation index at: https://docs.frogbot.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Barcode Field

> Store barcode values such as UPC or EAN codes as text.

`barcodeField` returns a [Text field](https://docs.frogbot.ai/fields/text.md) that stores a barcode value, such as a UPC or EAN code, as text. The admin panel shows the value as typed, and agents and generated types are told what the text means. You don't name any components.

```ts theme={"theme":"tokyo-night"}
import { barcodeField } from 'frogbot'
import type { CollectionConfig } from 'frogbot'

export const Products: CollectionConfig = {
  slug: 'products',
  fields: [
    { name: 'title', type: 'text', required: true },
    barcodeField({ name: 'sku', label: 'SKU', unique: true }),
  ],
}
```

The result is a plain `text` field, so it works anywhere a field does, including inside groups, arrays, tabs and blocks.

## Config options

| Option | Type | Default | Description |
| - | - | - | - |
| `name` | `string` | Required | Property name used in stored records and APIs. See [field names](https://docs.frogbot.ai/fields/overview.md#field-names). |
| `minLength` | `number` | — | Minimum length, checked by the built-in validator. |
| `maxLength` | `number` | Root `defaultMaxTextLength` (`40000`) | Maximum length, checked by the built-in validator. |
| `label` | `string \| Record<string, string> \| (({ i18n, t }) => string) \| false` | Generated from `name` | Label shown in the admin panel. Use an object keyed by language code for translations, or `false` to hide the label. |
| `required` | `boolean` | `false` | Rejects an empty value. |
| `unique` | `boolean` | `false` | Creates a unique database index for the field path. See [indexes](https://docs.frogbot.ai/database/indexes.md). |
| `index` | `boolean` | `false` | Creates a database index for faster queries. `unique` already creates one. |
| `localized` | `boolean` | `false` | Stores one value per configured locale. Ignored without [localization](https://docs.frogbot.ai/configuration/localization.md) or inside a localized parent. |
| `defaultValue` | `string` or `({ locale, req, user }) => value` | — | Value used when the field has no value. See [default values](https://docs.frogbot.ai/fields/overview.md#default-values). |
| `validate` | `Validate` | — | Runs after the built-in validation of `required`, `minLength` and `maxLength`, and adds to it rather than replacing it. Use it for a format rule such as a check digit. See [validation](https://docs.frogbot.ai/fields/overview.md#validation). |
| `hooks` | `{ beforeValidate, beforeChange, afterChange, afterRead, beforeDuplicate }` | — | Arrays of `FieldHook` functions for each phase. See [field hooks](https://docs.frogbot.ai/hooks/fields.md). |
| `access` | `{ create, read, update }` | Allowed | `FieldAccess` functions for each operation. See [field access control](https://docs.frogbot.ai/access-control/fields.md). |
| `hidden` | `boolean` | `false` | Removes the field from API responses and the admin panel while keeping stored data. |
| `saveToJWT` | `boolean \| string` | `false` | In an auth-enabled collection, copies the value into the user's token. A string sets the token key. See [token data](https://docs.frogbot.ai/authentication/token-data.md). |
| `virtual` | `boolean \| string` | `false` | `true` skips database storage; a string reads a value through a relationship path. Virtual fields are read-only in the admin panel unless `admin.readOnly` is `false`. See [virtual fields](https://docs.frogbot.ai/fields/overview.md#virtual-field-configuration). |
| `disableDuplicate` | `boolean` | `false` | Leaves the value out when a document is duplicated, so the copy uses `defaultValue`. |
| `admin` | `object` | — | Admin-panel options. See [Admin options](#admin-options). |
| `custom` | `Record<string, any>` | — | Server-only metadata for your own code and plugins. Use `admin.custom` for data the browser also needs. |
| `jsonSchema` | `Array<({ jsonSchema }) => JSONSchema4>` | — | Functions that modify the JSON Schema used by [type generation](https://docs.frogbot.ai/typescript/generating-types.md) and agents. They run after the barcode field's own entry. See [Agents and generated types](#agents-and-generated-types). |

A barcode field holds one value, so `hasMany`, `minRows` and `maxRows` are not accepted. TypeScript rejects them, and setting any of them from JavaScript fails at startup with an error naming the field:

```text theme={"theme":"tokyo-night"}
barcodeField "sku": hasMany is not supported
```

FrogBot doesn't check the barcode's format, so any text is accepted. Your own `minLength`, `maxLength` and `validate` apply on every save.

## Admin options

Barcode fields support the standard [field admin options](https://docs.frogbot.ai/fields/overview.md#admin-options), plus the Text field's input options:

| Option | Type | Default | Description |
| - | - | - | - |
| `placeholder` | `string \| Record<string, string>` | — | Placeholder text. Use an object keyed by language code for translations. |
| `autoComplete` | `string` | — | Value of the input's `autocomplete` attribute. |
| `rtl` | `boolean` | Follows the locale | `true` forces right-to-left text. `false` keeps left-to-right text in a right-to-left locale. When unset, right-to-left locales render right-to-left. |

FrogBot marks the field as a barcode in `admin.custom.frogbot.kind`. Your own `admin.custom` keys, and other keys under `admin.custom.frogbot`, are kept.

## Display and editing

A barcode shows as typed, as plain text, in the [List](https://docs.frogbot.ai/admin/overview.md), on [Board](https://docs.frogbot.ai/admin/collection-board.md) cards and in [Calendar](https://docs.frogbot.ai/admin/collection-calendar.md) events. An empty value shows nothing: no placeholder and no dash. If a barcode field is the first List column, a row with an empty value has no link to open the document from that column.

In the document view, a barcode field uses the normal text input. There is no camera scanning and no barcode image.

## Stored value

Only the barcode text is stored, with no barcode type such as UPC-A or EAN-13. The REST API, GraphQL and the Local API return the stored text, and the generated TypeScript type is the same as a Text field's, such as `sku?: string | null`.

> [!NOTE]
>
> If barcode scanning is added later, the stored value may change to hold the barcode type as well as the text.

## Agents and generated types

A barcode field describes itself to agents using FrogBot's [MCP tools](https://docs.frogbot.ai/plugins/mcp.md) and in [generated types](https://docs.frogbot.ai/typescript/generating-types.md):

```text theme={"theme":"tokyo-night"}
Barcode value as text, for example a UPC or EAN code
```

With a string `admin.description`, or a translated one with an `en` entry, the barcode text is added after it in parentheses. The admin panel still shows only your description.

```ts theme={"theme":"tokyo-night"}
barcodeField({ name: 'sku', admin: { description: 'Code printed on the box' } })
```

```text theme={"theme":"tokyo-night"}
Code printed on the box (barcode value as text, for example a UPC or EAN code)
```

A function `admin.description` isn't copied, so the barcode text stands alone. The text is English only. Generated types show the text as a comment above the property, and virtual fields don't appear in MCP tool inputs.

To change the text, add your own `jsonSchema` entry. It runs after the barcode field's entry, so it can adjust or replace the description:

```ts theme={"theme":"tokyo-night"}
barcodeField({
  name: 'sku',
  jsonSchema: [({ jsonSchema }) => ({ ...jsonSchema, description: '13-digit EAN code' })],
})
```

```text theme={"theme":"tokyo-night"}
13-digit EAN code
```

## Custom components

The barcode cell is `BarcodeCell` from `@frogbotai/ui/admin`. Your own `admin.components.Cell` replaces it, and `admin.components.Field` and other components such as `Label`, `Description`, `Error`, `beforeInput` and `afterInput` work as they do on a Text field.

A custom Cell can draw the standard display inside its own markup with [`FieldCell`](https://docs.frogbot.ai/fields/overview#cell), as shown for [Money fields](https://docs.frogbot.ai/fields/money.md#custom-components). As with any custom Cell, it appears only in the List view. Board cards and Calendar events keep the standard display.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.