> 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/taxonomies/term-fields.md).

# Term fields

Give every term of a taxonomy extra fields — for example a country's capital — with the schema builder.

**Where:** Database → Taxonomies → row menu → **Edit taxonomy** (or **Add New**) → **Term fields** tab · `/projects/<project>/db/taxonomies/<taxonomyName>/edit`

**Term fields** are extra fields that every term of one taxonomy has — `Capital` and `Population` for every term of `Countries`. You build them with the same builder as a collection schema — the same [field types](/codemash/cloud/database/schema/field-types.md) and the same two documents (data schema and UI schema, see the [Schema authoring guide](/codemash/cloud/database/schema.md)); each term keeps their values in its `meta`.

## Before you start

* The taxonomy exists, or you are creating it — see [Create a taxonomy](/codemash/cloud/database/taxonomies/new.md).
* You need `database:update` on the taxonomy (`database:taxonomy:<id>`, or `database:taxonomy:all`); `database:create` on `database:taxonomy:all` for a new one.

## Steps

1. Open the taxonomy form (**Edit taxonomy**, or **Add New**) and switch to the **Term fields** tab. It holds the builder: **Visual Builder**, **Preview** and **JSON**, and **Show fields panel**.
2. Add the fields — drag them from the fields panel into a container, or use **JSON** → **Edit JSON** and paste the data structure (top) and the UI structure (bottom), then **Save schemas' changes**. Example data structure:

   ```json
   {
     "$schema": "https://norbix.ai/schemas/meta/v1.json",
     "title": "Countries",
     "type": "object",
     "additionalProperties": true,
     "properties": {
       "capital": { "type": "string", "maxLength": 200 },
       "population": { "type": "integer", "minimum": 0 }
     }
   }
   ```

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-85e4e1b994be2b8bc6f067348c2b23f0c58900d0%2Fterm-fields-1.png?alt=media" alt="Term fields tab of Add New taxonomy: the text Extra fields every term of this taxonomy has, the Visual Builder with one tab Term and the fields Capital (6/12) and Population (6/12); Cancel and Save"><figcaption><p>Two term fields in the Visual Builder.</p></figcaption></figure>
3. Press **Save** (the same **Save** as on the **Taxonomy** tab). If the term fields are not valid — for example after a broken JSON edit — the form stays on **Term fields**, shows **The term fields cannot be saved** with the reasons, and saves nothing.

## Result

Every term form of the taxonomy now shows a **Term fields** section below the parents (*Extra fields of the Countries taxonomy*). Fill it on a term and press **Save** — see [Terms](/codemash/cloud/database/taxonomies/terms.md#what-you-can-do-here).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-db7b0188d1132f90d36f09c25acfe763dad9b171%2Fterms-2.png?alt=media" alt="The term form of Lithuania with the Term fields section: Capital Vilnius, Population 2800000"><figcaption><p>The term fields on a term.</p></figcaption></figure>

The API returns the values in the term's `meta`: `{ "capital": "Vilnius", "population": 2800000 }`.

## Change or remove it later

* **Change** — open the **Term fields** tab again, change the fields and press **Save**.
* **Remove** — delete every field and save: the taxonomy has no term fields again. Values already stored in terms stay in their `meta`; the form no longer shows them.
* A term form saves the whole `meta`: a field you empty is removed; keys written through the API that are not term fields are kept.

## Do it from code

```ts
const { item } = await norbix.hub.database.getDatabaseTaxonomy({ id: 'txn_2ecJhU8RtC0chrKoXPOMJR' });
console.log(Object.keys(JSON.parse(item.termsMetaDataSchema.json).properties)); // [ 'capital', 'population' ]
const terms = await norbix.api.database.findTerms({ taxonomyName: 'Countries' });
console.log(terms.list.items.map((t) => `${t.name}: ${t.meta?.capital}`));
// [ 'Lithuania: Vilnius', 'Latvia: Riga', 'Estonia: Tallinn' ]
```

```sh
norbix hub database taxonomy get --id txn_2ecJhU8RtC0chrKoXPOMJR
```

To set term fields from code, send `termsMetaDataSchema` and `termsMetaVisualSchema` (JSON strings) with `saveDatabaseTaxonomy`. The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Save Database Taxonomy](/codemash/api-reference/database/taxonomies/save-database-taxonomy.md) · [Get Database Taxonomy](/codemash/api-reference/database/taxonomies/get-database-taxonomy.md)
