Skip to main content
Learn how to use the ID Async Select component for handling foreign key relationships.

ID Async Select Overview

Async Loading

API callsAutocomplete

Type Safe

Entity basedID type guaranteed

Search Support

Real-time filteringDebounce

Multiple Selection

Single/Multiple modesArray return

What is ID Async Select?

Problem: Complexity of Foreign Key Selection

When handling foreign key relationships in databases, the frontend needs to select related entities. Problems with traditional approach:
Problems:
  1. Performance: Loading time increases with more data
  2. Memory: All unnecessary data loaded into memory
  3. UX: Hard for users to find desired items
  4. Scalability: Can’t handle continuous data growth

Solution: ID Async Select

Sonamu’s ID Async Select loads asynchronously only when needed and provides search functionality.
Benefits:
  1. Performance: Load minimum initially, only what’s needed on search
  2. User experience: Quick selection with autocomplete
  3. Type safe: Entity type automatically applied
  4. Scalability: No problem regardless of data volume

Basic Usage

Required Props

ID Async Select uses these two core props:
  • config: AsyncIdConfig object auto-generated from services.generated.ts
  • subset: Subset key to query (e.g., “A”, “D”, etc.)

Single Selection

Select one entity.
How it works:
  1. Call search API when user types
  2. Display search results in dropdown
  3. Only save ID when selected (memory efficient)

Multiple Selection

Select multiple entities.
Multiple selection features:
  • Display selected items as tags
  • Remove individually with X button
  • Return IDs as array (number[])

Setting Initial Values

Set initial values when editing existing data.
Initial value handling:
  • Passing ID to value automatically loads the entity
  • Background single query for label display
  • Display only ID while loading

displayField Options

Specify by Field Name

The simplest way - specify the field name as a string.

Specify by Callback Function

Use a callback function when complex labels are needed.

Auto Detection (Omit displayField)

When displayField is omitted, an appropriate field is automatically detected.
Detection priority:
  1. name-like fields: name, title, label, display_name, username
  2. First string type column (excluding id)
  3. fallback: id

Advanced Usage

Pass Search Conditions with baseListParams

Set default search parameters.

Get Full Row Data with onRowChange

When you need the full selected Row data, not just the ID:

Change valueField

By default, the id field is used as the value, but you can use a different field.

Type Safety

AsyncIdConfig Structure

The Config auto-generated from services.generated.ts has this structure:

Utilizing Type Inference

Types are automatically inferred through Config:

Practical Examples

Post Creation Form

Hierarchical Selection

Pattern of selecting child after parent.

Using with Forms

Example using with Sonamu’s useForm.

Props Reference

preload and searchable Combinations

The component’s rendering mode changes depending on preload and searchable values:
When baseListParams contains meaningful filter values, the component also behaves in sync dropdown mode, the same as preload.

Cautions

Cautions when using ID Async Select: 1. config should use objects auto-generated from services.generated.ts 2. subset must be a valid Subset key defined in the Entity 3. Verify array type for multiple selection 4. Field specified in displayField must be included in the Subset 5. Error handling required for initial value loading failure

Next Steps

View Scaffolding

Auto view generation

Search Input

Search component

Custom Components

Component customization

Using Services

Service integration