# Field configuration

Configure field types for your model with validations, visibility options, and more.

## Settings

Each field must have the following settings configured to be added to a model:

| Property     | Description                                                          |
| ------------ | -------------------------------------------------------------------- |
| Display name | This is what is shown to content editors throughout the application  |
| API ID       | This is what is exposed within the API as a field within your model. |
| Description  | Displays a hint for content editors and API users.                   |

Not all setting options are available for all [field types](https://hygraph.com/classic-docs/api-reference/schema/field-types).

### Use as a title field

You can set multiple fields as titles to appear within the relational picker instead of IDs.

**Note:**

You cannot use this when the field visibility is set to hidden, API only or read only.

To set a field as title field, select the `Use as title field` checkbox in the field details `Settings` tab:

![Use as a title field](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/use-as-title.png)

**Are you using the Management SDK?:**

To set your field as title, add the following parameter: **isTitle:\`true\`**

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#create-simple-fields)

### Allow multiple values

You should select this if you wish to accept multiple values, and return an array to the API for this field.

**Note:**

You cannot use the title field with this option.

To allow multiple values, select the `Allow multiple values` checkbox in the field details `Settings` tab:

![Allow multiple values](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/allow-multiple-values.png)

This checkbox can only be selected during field creation and will be read-only after that.

**Are you using the Management SDK?:**

To make your field allow multiple values, add the following parameter: **isList:\`true\`**

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#create-simple-fields)

### Localize field

Enabling this field allows translations per locale configured on your project.

**Note:**

You cannot use "Set initial value" with this option.

To make a field localized, select the `Localize field` checkbox in the field details `Settings` tab:

![Localize field](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/localize-field.png)

**Are you using the Management SDK?:**

To make your field localized, add the following parameter: **isLocalized:\`true\`**

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#create-simple-fields)

### Embed options

This setting is only available for Rich text fields.

**Rich text embeds need to be enabled per field**. You can do this from inside the Field Settings when adding a new, or editing a Rich Text field. Click _Enable embedding_ and select the models that should be embeddable in your Rich text field.

![Rich Text Options](https://hygraph.com/images/classic-docs/api-reference/schema/rich-text-embed-options.png)

## Validations

Not all validation options are available for all [field types](https://hygraph.com/classic-docs/api-reference/schema/field-types).

### Make field required

Marking this prevents content from being saved if it is left empty. The API will mark this field as non nullable.

**Note:**

You cannot use this when the field visibility is set to hidden, API only or read only.

To make a field required, select the `Make field required` checkbox in the field details `Validations` tab:

![Make field required](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/make-field-required.png)

**Are you using the Management SDK?:**

To make your field required, add the following parameter: **isRequired:\`true\`**

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#create-simple-fields)

### Set field as unique

Enabling this ensures content cannot be saved if the same value exists within another entry for this field. Uniqueness is checked per **Content stage**.

To set a field as unique, select the `Set field as unique` checkbox in the field details `Validations` tab:

![Set field as unique](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/set-field-unique.png)

**Are you using the Management SDK?:**

To make your field required, add the following parameter: **isUnique:\`true\`**

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#create-simple-fields)

### Limit character count

This validation allows you to specify the minimum/maximum character counts. You can set At least, Between, and No more than, with a custom error message.

To specify a minimum/maximum character count, select the `Limit character count` checkbox in the field details `Validations` tab:

![Limit character count](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/limit-character-count.png)

You can select a condition, add a minimum, a maximum and even specify an error message.

**Are you using the Management SDK?**

Here's an example of a field with a character count limit:

  **Custom field validation**

```graphql
client.createSimpleField({
parentApiId: '<parent_api_id>',
type: SimpleFieldType.Int,
apiId: '<api_id>',
displayName: '<Your Display Name>',
visibility: VisibilityTypes.Hidden,
validations: {
    Int: {
    range: {
        max: 1000,
        min: 0,
        errorMessage: '<Counter has to be between 0 and 1000>',
    },
    },
},
});
```


### Match a specific pattern

This validation allows you to only accept a specific regular expression.

To match a specific pattern, select the `Match a specific pattern` checkbox in the field details `Validations` tab:

![Match a specific pattern](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/match-field-pattern.png)

You must select a type and write a regular expression. You can indicate if the pattern should be case insensitive, multi/single line, and you can include a custom error message.

**Are you using the Management SDK?**

Here's an example of a field with a set RegEx value to match:

  **Custom regex validation for emails**

```graphql
client.createSimpleField({
  parentApiId: '<parent_api_id>',
  type: SimpleFieldType.String,
  apiId: '<email>',
  displayName: '<Email>',
  isRequired: true,
  isUnique: true,
  validations: {
    String: {
      matches: {
        regex: '^([a-z0-9_\\.\\+-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$',
      },
    },
  },
});
```


#### Common patterns

You can use an existing common pattern from the web app, or provide your own.

**URL**

```
(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)
```

**Phone**

```
^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$
```

**Email**

```
^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$
```

**Slug**

```
^[a-z0-9]+(?:-[a-z0-9]+)*$
```

#### Unicode characters

Hygraph field validations support unicode (non-latin) characters. You can add Unicode character classes - which typically correspond to specific alphabets - to a custom Regular Expression field validation.

You can read about the syntax [here](https://github.com/google/re2/wiki/Syntax).

### Restrict a specific pattern

This validation option allows you to _not_ accept specific regular expression.

**Note:**

Both Match and Restricting patterns are defined by standard Regular Expressions (RegExp) and do not need to be wrapped in opening or closing slashes.

You can modify these pattern searches with additional flags such as ignoring case, enabling multi-line search, single-line search or both.

To restrict a specific pattern, select the `Restrict a specific pattern` checkbox in the field details `Validations` tab:

![Restrict a specific pattern](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/restrict-field-pattern.png)

You must write a regular expression. You can indicate if the pattern should be case insensitive, multi/single line, and you can include a custom error message.

## Advanced

Not all advanced settings are available for all [field types](https://hygraph.com/classic-docs/api-reference/schema/field-types).

### Set initial value

You can define an initial value for content editors. This doesn't have any effect on the API when performing mutations.

**Note:**

You cannot use this when the field visibility is set to hidden, API only or read only.

To set an initial value for a field field, select the `Set initial value` checkbox in the field details `Advanced` tab, and add the value there:

![Set initial value](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/set-initial-value.png)

**Are you using the Management SDK?:**

To set the initial value for a field, use the `initialValue` parameter to pass a value.

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#update-simple-field)

### Field visibility

| Option       | Description                                                                                                                                                                           |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Read / Write | The field will be accessible for read/write operations. Default.                                                                                                                      |
| Read Only    | The field will be shown, but cannot be edited in the UI. You can update via the API if required.                                                                                      |
| Hidden       | The field will not be shown in the UI, but can be referenced by other fields such as [Slugs](https://hygraph.com/classic-docs/api-reference/schema/field-types#string), or [UI Extensions](https://hygraph.com/classic-docs/ui-extensions). |
| API Only     | Field is not shown in the UI, but can be used via the API using mutations.                                                                                                            |

**Note:**

Field visibility has no relation with permissions or security.

To select a field visibility type, use the field visibility dropdown menu to select an option. You will find it in the field details `Advanced` tab:

![Field visibility](https://hygraph.com/images/classic-docs/api-reference/schema/field-configuration/field-visibility.png)

**Are you using the Management SDK?:**

To indicate field visibility, use the `visibility` parameter to pass a type.

Visibility options:
- `visibility: "READ_WRITE"`
- `visibility: "READ_ONLY"`
- `visibility: "HIDDEN"`
- `visibility: "API_ONLY"`

[Here's an example!](https://hygraph.com/classic-docs/api-reference/management-sdk/management-sdk-field-examples#update-simple-field)
