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:- Performance: Loading time increases with more data
- Memory: All unnecessary data loaded into memory
- UX: Hard for users to find desired items
- 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.- ✨ Performance: Load minimum initially, only what’s needed on search
- ✨ User experience: Quick selection with autocomplete
- ✨ Type safe: Entity type automatically applied
- ✨ Scalability: No problem regardless of data volume
Basic Usage
Required Props
ID Async Select uses these two core props:config: AsyncIdConfig object auto-generated fromservices.generated.tssubset: Subset key to query (e.g., “A”, “D”, etc.)
Single Selection
Select one entity.- Call search API when user types
- Display search results in dropdown
- Only save ID when selected (memory efficient)
Multiple Selection
Select multiple entities.- 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.- Passing ID to
valueautomatically 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)
WhendisplayField is omitted, an appropriate field is automatically detected.
- name-like fields:
name,title,label,display_name,username - First string type column (excluding id)
- 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, theid field is used as the value, but you can use a different field.
Type Safety
AsyncIdConfig Structure
The Config auto-generated fromservices.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’suseForm.
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
Next Steps
View Scaffolding
Auto view generation
Search Input
Search component
Custom Components
Component customization
Using Services
Service integration