# Select

## Overview

The Select component allows users to select the necessary records from the list. If you search in our Components list, you will find two Select components available, one of them in the *Deprecated* section.

* **Deprecated** Select component - a classic version of the component that requires a list of options or a JS array with a specific structure, such as `[{ value: 1, title: 'Name' }];`.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FZ0ECAFgroJHaOL8T9zT8%2FCleanShot%202025-08-20%20at%2012.30.02%402x-min.png?alt=media&#x26;token=c90a1637-46e5-4611-94a1-b40d06d8594a" alt=""><figcaption></figcaption></figure>

* **Newer** Select component - an enhanced version of the component with additional functionality.\
  The component can take in an array of any structure, and users can specify which data keys to use as the option's *id* and *title*. Additionally, the updated version allows customization of per-option styles, including options colors and data types (for example, Date/Time, Text, Number, etc.).

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FUigbfIE5XZOdF7U9DKIC%2FCleanShot%202025-08-20%20at%2012.42.00%402x-min.png?alt=media&#x26;token=090f1d68-a844-4668-9dd1-b1421bf6a17d" alt=""><figcaption></figcaption></figure>

### Properties

<table><thead><tr><th width="182.17578125">Name</th><th width="214.43359375">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>Component name</td></tr><tr><td><code>value</code></td><td><p><code>string | undefined |</code> </p><p><code>(string | undefined)[]</code></p></td><td>Current component value</td></tr><tr><td><code>autocompleteValue</code></td><td><code>string</code></td><td>Component autocomplete value</td></tr><tr><td><code>valid</code></td><td><code>boolean</code></td><td>Indicates if the component is valid</td></tr><tr><td><code>validating</code></td><td><code>boolean</code></td><td>Indicates if the component is validating</td></tr><tr><td><code>disabled</code></td><td><code>boolean</code></td><td>Indicates whether the component is disabled</td></tr><tr><td><code>options</code></td><td><code>SelectOption[]</code></td><td>Component options</td></tr></tbody></table>

### Methods

<table><thead><tr><th width="150.21875">Name</th><th width="172.76953125">Parameters</th><th width="100.59765625">Returns</th><th>Description</th></tr></thead><tbody><tr><td><code>setValue</code></td><td><code>value: any</code></td><td><code>void</code></td><td>Set component value</td></tr><tr><td><code>setOptions</code></td><td><code>options: object[]</code></td><td><code>void</code></td><td><p>Set options for the select. Options is an array of objects with the following structure:<br><code>{</code><br></p><p><code>value: any;</code><br></p><p><code>title: string;</code><br></p><p><code>}</code></p></td></tr><tr><td><code>setDisabled</code></td><td><code>disabled: boolean</code></td><td><code>void</code></td><td>Disable or enable the component</td></tr><tr><td><code>reset</code></td><td>–</td><td><code>void</code></td><td>Reset the component to the initial value</td></tr><tr><td><code>validate</code></td><td>–</td><td><code>void</code></td><td>Trigger component validation</td></tr><tr><td><code>resetValidation</code></td><td>–</td><td><code>void</code></td><td>Clear validation errors</td></tr><tr><td><code>setErrors</code></td><td><p><code>errors: string |</code></p><p> <code>string[] | null</code></p></td><td><code>void</code></td><td>Mark the component as invalid and display errors</td></tr><tr><td><code>setRequired</code></td><td><code>required: boolean</code></td><td><code>void</code></td><td>Set component required state</td></tr></tbody></table>

### Triggers

<table><thead><tr><th width="130.88671875">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>On Change</strong></td><td>Triggered when the component's state changes</td></tr><tr><td><strong>On Focus</strong></td><td>Triggered when the component is in focus</td></tr><tr><td><strong>On Blur</strong></td><td>Triggered when the component loses focus</td></tr><tr><td><strong>On Init</strong></td><td>Triggered when the component is initialized</td></tr></tbody></table>

## Working with the component

### Loading options from an API or database

Using Select, you can load options dynamically from the server without the need to map the loaded data. Depending on the type of Select you're using (deprecated or new), you will have to do the following to load the data:

* **(New)** Assign your action or reference the component that returns an array of objects and set the display of these values in the Select by configuring the *Option title* and *Option value* properties.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FqP1wPt4z8FW43NvnzSPN%2FCleanShot%202025-08-21%20at%2014.37.38%402x-min.png?alt=media&#x26;token=82e68eee-b407-4f66-a0ed-9deb3cb695ff" alt=""><figcaption></figcaption></figure>

* **(Deprecated)** The basic flow here is to specify your options in the form of an array of objects with *value* and *title* keys, for example, `[{ value: 1, title: 'Name' }]`.\
  Here's how you can do that:

1. Create an action that loads the data you need, for example, a *Load Table* action to load a list of users.
2. Next, add another step to your Load Table action, select *JavaScript Code* action, and specify the following code to transform data into an array of value/title objects:

```javascript
return {{data}}.map((item) => {
  return { value: item.id, title: item.name };
});
```

3. Click on the Select component, switch to the *JS* mode in the **Options** field, and assign your *load data* action there.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FFur9WhJ1jiUGZmywngPE%2FCleanShot%202025-08-21%20at%2014.56.06%402x-min.png?alt=media&#x26;token=03f80bb3-a41c-4975-8b0b-8f5cf919db8a" alt=""><figcaption></figcaption></figure>

Done! Now the deprecated Select component will display a list of options loaded dynamically.

#### Setting an array of strings as Select options

Another option for the deprecated Select component, if your API returns an array of primitives like strings/numbers, you can the array directly inside the *Options* field without the need to create a value/title object. In this scenario, to extract the options for the Select, you can create an *array of strings* and use it in the component.

Here's how you can do that:

1. Create an action loading your data (in our example, it's an *HTTP API* step), turn on the **Transform result** toggle, and add the following code to create an array of strings in the mapper:

```javascript
return {{data}}.map(item => item.name)
```

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FQocxlVxLCli2dkU2xWSh%2FCleanShot%202025-08-22%20at%2012.11.15%402x-min.png?alt=media&#x26;token=00fe388e-baaf-45ae-b5a0-e369dc0468c7" alt=""><figcaption></figcaption></figure>

2. Run the action and you'll see the list of names in the *Result* tab that you can use in the Select component.
3. Now, click on the Select component, switch to the *JS* mode in the **Options** field, and assign your *load data* action there.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FhH6LqbVqnOZGgl1ctsBY%2FCleanShot%202025-08-22%20at%2012.13.32%402x-min.png?alt=media&#x26;token=d5a575a7-d421-4411-b896-77b0a2f7f53b" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
In this scenario, the name will be used both as the *title* and the *value* of the option. If you need to use a different title for the option, you will need to [map the data](#loading-options-from-an-api-or-database) to the UI Bakery format of  `{value, title}`.
{% endhint %}

### Setting a default value

You can pre-select a specific option for the component by specifying the value you need in the Select's *Value* field.&#x20;

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FyeeD91P2Qvh2rFA1S1WF%2FCleanShot%202025-08-21%20at%2015.36.14%402x-min.png?alt=media&#x26;token=206386e7-7b2e-4e86-9ec9-6e3b6ec87605" alt=""><figcaption></figcaption></figure>

You can also set the component's value dynamically, for example, referencing a value from another component in the Select's *Value* field.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FwvG0nnkLvkTSfG7UiuXQ%2FCleanShot%202025-08-21%20at%2015.45.22%402x-min.png?alt=media&#x26;token=96e6ff77-5927-4d9c-8e61-ffd0dd048090" alt=""><figcaption></figcaption></figure>

### Using autocomplete

If you have a lot of options to choose from, you can enable autocomplete to improve navigation. It will allow users to quickly search through the available options.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FCAE61bOwqYY1sZc8esJj%2FCleanShot%202025-08-21%20at%2015.56.58%402x-min.png?alt=media&#x26;token=0871e3ee-5039-4330-a0d1-c2ac4e217f54" alt=""><figcaption></figcaption></figure>

### Enabling multiple selection

It is also possible to allow multiple options select for the component by enabling the *Multiple select* setting.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FUGpJ7UZD1K87Iv7XEKIr%2FCleanShot%202025-08-22%20at%2011.47.25%402x-min.png?alt=media&#x26;token=107f0430-f1d4-49f4-9aa1-1bdd126c415e" alt=""><figcaption></figcaption></figure>

If you want to set a default value of a multiple select, you will need to put the array in the curly braces because the Select's *Value* setting is treated as a string by default:

```javascript
{{ [‘option 1’, ‘option 2’] }}
```
