Skip to main content
io.select.single() asks to pick one option from a searchable drop-down and returns the chosen option itself: a { value, label } object, an enum member or a record from your database. Provided by the @awaitio/select-single package.
A New role drop-down open on Admin, Editor and Viewer, with Editor chosen and a × to clear it

Install

Setup

Register it under the key you want in io, see Input components:
app.ts

Usage

Options can be records as they come from the database. Say how to identify and name them with key and label; the handler gets the record back, relations and dates included:
Strings and numbers, such as the members of an enum, name themselves:
The options stay on the server. The browser gets only their labels and answers with the position of the chosen one, so values do not have to be strings and nothing that is not shown leaves the server.

Props

Optional

The field is required. Chain .optional() to let it stay empty; the handler then gets the option or undefined, see Optional fields.

Returns

The chosen option itself, typed by options: the same object you passed, not a copy.

Built-in validation

The server checks every answer, so a crafted request cannot slip in another value:

Custom validation

Chain .validate() for a check of your own. It runs on the server after the checks above, gets the value the handler would get and returns a message to show under the field, or nothing when the value is fine; see Custom validation.