Skip to main content
Learn how to implement dynamic field search by combining SearchFieldSelect with Input. Users can select a search field (ID, name, email, etc.) and enter keywords.

Core Features

Dynamic Search

Select field + keyword combinationFlexible search conditions

Auto-generated

SearchField enum basedAuto label mapping

useListParams Integration

register pattern supportAuto URL sync

Backend Pattern

exhaustive patternType-safe implementation

Auto-generation Conditions

SearchFieldSelect is auto-generated when the SearchField enum is defined in the backend.

Backend Definition

Auto-generated Files

Component location: web/src/components/user/UserSearchFieldSelect.tsx Auto-generated labels: web/src/services/sonamu.generated.ts
SearchField vs keyword
  • search: Search target field selection (ID, name, email, etc.)
  • keyword: Actual search term input
Both must be used together to implement search functionality.

Basic Usage

SearchFieldSelect + Input Combination

How it works:
  1. User selects search field (ID, name, email)
  2. User enters keyword
  3. listParams is updated and API is called
  4. Backend searches the specified field with the keyword

Props

UserSearchFieldSelect Props

Common Props

Backend Implementation

Handling in Model

Key Points:
  1. Check both search and keyword: Search only when both exist
  2. Different processing per field:
    • ID: Exact match with number conversion
    • Name/Email: Partial match with LIKE
  3. Type safety with exhaustive(): Compile error if case is missing
exhaustive Pattern
If a new option is added to SearchField enum, this line will cause a compile error, ensuring the developer doesn’t forget to handle it.

Real-world Examples

Complete Search Filter

By default, search occurs automatically as you type. To search only when button is clicked:

Conditional Placeholder

Change placeholder based on selected search field:

Display Current Search Condition

To search multiple fields simultaneously:

Customization

SearchFieldSelect is a scaffolding file, so you can modify it freely.

Change Labels

Hide Specific Options

Add Icons

Troubleshooting

SearchFieldSelect Not Generated

Cause: SearchField enum not defined in backend Solution:

Search Not Working

Cause: Backend Model missing search and keyword handling Solution: Add search logic to user.model.ts’s findMany.

ID Search Returns No Results

Cause: Keyword not converted to number Solution: