> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/schema/field-types/text.md).

# Text

A text field: a string with length, pattern and uniqueness rules, shown as a single-line textbox.

A **Text** field stores one string — a title, a name, a code. The data schema sets how long it may be, which pattern it must match and whether it must be unique in the collection.

**Builder:** Form fields panel → **Text** · widget `text` · data type `string.schema.v1`

## Data schema

```json
{
  "title": {
    "type": "string",
    "minLength": 2,
    "maxLength": 200,
    "pattern": "^[A-Z].*",
    "default": "Untitled",
    "unique": false
  }
}
```

| Keyword                 | Required | What it does                                                                                                                                        | Example                    |
| ----------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
| `type`                  | yes      | Always `"string"`.                                                                                                                                  | `"string"`                 |
| `minLength`             | no       | The fewest characters allowed (0 or more).                                                                                                          | `2`                        |
| `maxLength`             | no       | The most characters allowed.                                                                                                                        | `200`                      |
| `pattern`               | no       | A .NET regular expression the whole value must match.                                                                                               | `"^[A-Z].*"`               |
| `default`               | no       | The value a new record gets when the field is left out. Must follow the rules above.                                                                | `"Untitled"`               |
| `unique`                | no       | `true` = no two records of the collection (per environment) share the value.                                                                        | `true`                     |
| `format`                | no       | `email` or `uri` — see [Email](/codemash/cloud/database/schema/field-types/email.md) and [URI](/codemash/cloud/database/schema/field-types/uri.md). | `"email"`                  |
| `meta.translateOptions` | no       | One value per language — see [Translatable text](/codemash/cloud/database/schema/field-types/translatable.md).                                      | `{ "translatable": true }` |
| `title`, `description`  | no       | Free text about the field. The form label comes from the UI schema, not from here.                                                                  | `"Book title"`             |

### What the server refuses

Every write — insert, update, replace; from Cloud, the API, an SDK, the CLI or an AI agent — is checked against the published schema. A broken value is answered with one error per field: the code, and `Field '<name>' is invalid: <reason>`. Nothing is written.

| Case                                               | Code                     | The reason it gives              |
| -------------------------------------------------- | ------------------------ | -------------------------------- |
| a required field is missing or `null`              | `CM-ERRORS-DATABASE-030` | `a value is required`            |
| the value is not a string (a number, an object, …) | `CM-ERRORS-DATABASE-039` | `must be a string`               |
| shorter than `minLength`                           | `CM-ERRORS-DATABASE-040` | `must be at least 2 characters`  |
| longer than `maxLength`                            | `CM-ERRORS-DATABASE-040` | `must be at most 200 characters` |
| does not match `pattern`                           | `CM-ERRORS-DATABASE-041` | `must match pattern ^[A-Z].*`    |

A keyword that is not in the table above is refused when the schema is **saved**, not when a record is written: `CM-ERRORS-SCHEMA-010` — `Data schema violates meta-schema: Property 'sort' has not been defined and the schema does not allow additional properties. Path 'properties.title.sort' (field 'properties.title' checked as string.schema.v1).`

Also refused at save time:

* `minLength` above `maxLength` — `CM-ERRORS-SCHEMA-022` `Schema field 'title' has an invalid range: …`.
* a `pattern` that is not a valid regular expression — `CM-ERRORS-SCHEMA-023` `Schema field 'title' has an invalid regex pattern '[': …`.
* a `default` that breaks the field's own rules (too long, wrong type) — `CM-ERRORS-SCHEMA-037` `Schema field 'title' has an invalid default: …`.

## UI schema

The cell uses the `text` widget. For a multi-line box or a code editor use `textarea` / `html` — see [Long text and HTML](/codemash/cloud/database/schema/field-types/textarea-html.md).

```json
{
  "colSpan": 6,
  "element": {
    "fieldId": "title",
    "meta": { "widget": "text", "label": "Title", "placeholder": "Enter a title", "help": "Starts with a capital letter", "required": true }
  }
}
```

Every cell also takes the common layout options: `label`, `placeholder`, `help` (the text under the input), `required`, `readonly` and `hidden`. Keys outside this list — `watermark`, `hint`, `permissions` — are refused when the schema is saved (`CM-ERRORS-SCHEMA-012`), see [Schema authoring guide](/codemash/cloud/database/schema.md#one-contract-no-second-dialect).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-ebf915cf71f4945a3c0d5bf9ef1529c892da44f4%2Ffield-types-text-1.png?alt=media" alt="Add New Record form of sc_e2e_all_types, Text tab: String plain with a placeholder and a help text, String type, String format email with an envelope icon, String format uri, String pattern, and String min length as a dark code editor"><figcaption><p>The Text tab of the generated all-types form: text, email, website and html widgets.</p></figcaption></figure>

## Records

A record the schema accepts:

```json
{ "title": "The Dispossessed" }
```

A record it refuses:

```json
{ "title": "the dispossessed" }
```

The answer: `CM-ERRORS-DATABASE-041` — `Field 'title' is invalid: must match pattern ^[A-Z].*`. In Cloud the same sentence is shown under the field before the form is sent; the server repeats the check on every API write.

## Good to know

* `unique` is checked against the stored records of the collection in that environment, not by the per-field rules — so it has no `CM-ERRORS-DATABASE-0xx` code of its own.
* `maxLength` counts characters, not bytes.
* A text field can be used as the `displayField` of a [collection reference](/codemash/cloud/database/schema/field-types/collection-reference.md) — the value other collections show instead of the record id.

## Do it from code

```ts
await norbix.api.database.insertOne({
  collectionName: 'books',
  document: JSON.stringify({ title: 'The Dispossessed' }),
});
```

```sh
norbix api database one insert --collectionName books --document '{"title":"The Dispossessed"}'
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Save Database Schema](/codemash/api-reference/database/schemas/save-database-schema.md)

## Related

[Long text and HTML](/codemash/cloud/database/schema/field-types/textarea-html.md) · [Email](/codemash/cloud/database/schema/field-types/email.md) · [URI](/codemash/cloud/database/schema/field-types/uri.md) · [Translatable text](/codemash/cloud/database/schema/field-types/translatable.md) · [Field type reference](/codemash/cloud/database/schema/field-types.md) · [Schema authoring guide](/codemash/cloud/database/schema.md) · [Create a schema](/codemash/cloud/database/collections/create-schema.md)
