You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Lookup Field component provides a reference field for creating relationships between objects and records.
8
+
The Lookup Field component provides a reference field for creating relationships between objects and records. It supports dynamic data loading from a DataSource with debounced search, loading/error/empty states, keyboard navigation, and optional quick-create entry.
9
9
10
10
## Basic Usage
11
11
@@ -62,24 +62,51 @@ interface LookupFieldSchema {
62
62
// Reference Configuration
63
63
reference_to: string; // Referenced object/table name
64
64
reference_field?: string; // Field to display (default: 'name')
65
+
description_field?: string; // Secondary field shown below label
66
+
id_field?: string; // ID field on records (default: '_id')
65
67
options?: LookupOption[]; // Available options (if static)
66
68
67
-
// Data Source (for dynamic lookups)
68
-
dataSource?: {
69
-
api?: string; // API endpoint
70
-
method?: string; // HTTP method
71
-
params?: Record<string, any>; // Query parameters
72
-
};
69
+
// Data Source (automatic via SchemaRendererContext, or explicit)
70
+
// When a DataSource is available, the popup dynamically loads
71
+
// records from the referenced object on open, with debounced search.
72
+
dataSource?: DataSource;
73
+
74
+
// Quick-create callback (shown when no results found)
75
+
onCreateNew?: (searchQuery: string) => void;
73
76
}
74
77
75
78
interface LookupOption {
76
79
label: string; // Display label
77
80
value: string; // Record ID
81
+
description?: string; // Secondary text below label
78
82
_id?: string; // Alternative ID field
79
83
name?: string; // Alternative label field
80
84
}
81
85
```
82
86
87
+
## Dynamic Data Source
88
+
89
+
When a `DataSource` is available (via `SchemaRendererContext`, explicit prop, or field config), the Lookup popup **automatically** fetches records from the referenced object:
90
+
91
+
```plaintext
92
+
// Automatic — DataSource from SchemaRendererContext
93
+
// (works out-of-the-box in ObjectForm, DrawerForm, etc.)
94
+
{
95
+
type: 'lookup',
96
+
name: 'customer',
97
+
label: 'Customer',
98
+
reference_to: 'customers',
99
+
reference_field: 'name', // Display field (default: 'name')
100
+
description_field: 'industry', // Optional secondary field
101
+
}
102
+
```
103
+
104
+
The popup will:
105
+
1. Fetch records via `dataSource.find(reference_to, { $top: 50 })` on open
106
+
2. Send `$search` queries with 300ms debounce as the user types
107
+
3. Show loading spinner, error state with retry, and empty state
108
+
4. Display "Showing X of Y" when more records exist than the page size
109
+
83
110
## Lookup vs Master-Detail
84
111
85
112
-**Lookup**: Standard reference field, can be deleted independently
@@ -104,31 +131,14 @@ import { LookupCellRenderer } from '@object-ui/fields';
104
131
-**Parent Records**: Master-detail relationships
105
132
-**Team Members**: Multi-user references
106
133
107
-
## Dynamic Data Source
108
-
109
-
For lookups that fetch data from an API:
110
-
111
-
```plaintext
112
-
{
113
-
type: 'lookup',
114
-
name: 'customer',
115
-
label: 'Customer',
116
-
reference_to: 'customers',
117
-
dataSource: {
118
-
api: '/api/customers',
119
-
method: 'GET',
120
-
params: {
121
-
active: true,
122
-
limit: 100
123
-
}
124
-
}
125
-
}
126
-
```
127
-
128
134
## Features
129
135
130
-
-**Search**: Type-ahead search in options
136
+
-**Dynamic DataSource Loading**: Automatically fetches records from referenced objects
137
+
-**Search**: Debounced type-ahead search with `$search` parameter
131
138
-**Multi-Select**: Support for multiple references
132
-
-**Lazy Loading**: Load options on demand
133
-
-**Relationships**: Create data relationships
134
-
-**Cascading**: Support for dependent lookups
139
+
-**Keyboard Navigation**: Arrow keys to navigate, Enter to select
140
+
-**Loading/Error/Empty States**: Friendly feedback for all states
141
+
-**Secondary Field Display**: Show description/subtitle per option
142
+
-**Quick-Create Entry**: Optional "Create new" button when no results
143
+
-**Pagination Hint**: Shows total count when more results available
144
+
-**Backward Compatible**: Falls back to static options when no DataSource
0 commit comments