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 theSearchField 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
Basic Usage
SearchFieldSelect + Input Combination
- User selects search field (ID, name, email)
- User enters keyword
listParamsis updated and API is called- Backend searches the specified field with the keyword
Props
UserSearchFieldSelect Props
Common Props
Backend Implementation
Handling in Model
- Check both
searchandkeyword: Search only when both exist - Different processing per field:
- ID: Exact match with number conversion
- Name/Email: Partial match with LIKE
- Type safety with exhaustive(): Compile error if case is missing
exhaustive PatternIf 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
Search Button (Manual Search)
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
Advanced Search
Multi-field Search
To search multiple fields simultaneously:Case-insensitive Search
Regular Expression Search
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 missingsearch 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:Related Documentation
- auto-generated-overview - Auto-generated components overview
- OrderBySelect - Sort selection
- useListParams - List filtering hook