---
title: "code"
image: "https://adonia.pages.dev/og.png"
version: "next"
---

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

# code

<!-- Generated by `pnpm docs:fields` from packages/core/src/schema/fields/code.ts. Edit the TSDoc, not this file. -->

Source-code editor bound to a string attribute.

Unlike every other string field, `code` does NOT trim: leading
indentation and a trailing newline are content in a source file, and a
validator that quietly removed them would corrupt what the author typed.

| | |
| --- | --- |
| Builder | `F.code(attribute: string): CodeField` |
| Wire type key | `code` |
| Class chain | `CodeField` → `Field` |
| Detail projection | `code-entry` |
| Column counterpart | — *(not tabulatable)* |

## Example

```ts
import { F } from '@adonia/core'

F.code('template').label('Template').language('html').rows(20).lineNumbers()
```

## Props

Beyond the shared [field DSL](/reference/fields#the-shared-field-dsl):

| Prop | Declared on | Behaviour |
| --- | --- | --- |
| `language(name: string): this` | `CodeField` | Highlighter grammar name (`'sql'`, `'html'`, `'ts'`, …), passed through to the client editor and to the `code-entry` detail projection. Purely a rendering hint — the server never parses the content. |
| `rows(count: number): this` | `CodeField` | Initial editor height in rows; the client's default applies when unset. |
| `lineNumbers(enabled = true): this` | `CodeField` | Renders a line-number gutter (default off). |
| `wrap(enabled = true): this` | `CodeField` | Soft-wraps long lines instead of scrolling horizontally (default off). |

## Validation

Vine base: `vine.string()`.

§11.1 mapping: `vine.string()` with the declared length bounds, and
deliberately no `trim()` — see the class note.

Contributed by `CodeField.vineSchema()` in `packages/core/src/schema/fields/code.ts`. The shared modifiers (`required`, `nullable`, `requiredWhen`, `unique`, optionality) are applied on top by `Field.buildValidation`, and a `rules()` override replaces the base entirely — the validator compiler never branches on the field class.

## Declared in

- `packages/core/src/schema/fields/code.ts` — `CodeField`

Source: https://adonia.pages.dev/reference/fields/code/index.mdx
