- Name:
relation
- UI: Text input with search result dropdown
- Data type: Data type of the value pulled from the related collection item
The relation widget allows you to reference items from another collection. It provides a search input with a list of entries from the collection you are referencing, and the list automatically updates with matched entries based on what you have typed.
Widget Options
For common options, see Common widget options.
Name 17419_1fb4ef-d2> |
Type 17419_65aad6-7c> |
Default 17419_8e1f6b-e7> |
Description 17419_15300f-3c> |
---|---|---|---|
collection 17419_06c2f5-65> |
string 17419_ef0bf1-80> | 17419_e75776-26> |
Name of the referenced collection 17419_682e7a-3c> |
value_field 17419_54dec7-36> |
string 17419_144608-cd> | 17419_2c2bcd-36> |
Name of the field from the referenced collection whose value will be stored for the relation. For nested fields, separate each subfield with a |
search_fields 17419_a31679-d6> |
list of strings 17419_d50b9a-11> | 17419_a940ca-49> |
List of one or more names of fields in the referenced collection to search for the typed value. Syntax to reference nested fields is similar to that of value_field 17419_ebacdd-d8> |
default 17419_633e09-43> |
Any widget data type 17419_dcf184-0c> |
|
Optional. The default value for the field. Accepts any widget data type 17419_ed1a7f-4b> |
file 17419_1e776e-4d> |
string 17419_904af0-4e> | 17419_ab5626-29> |
Optional. Allows referencing a specific file when the referenced collection is a files collection 17419_cd1785-aa> |
display_fields 17419_634c15-f6> |
list of strings 17419_76115d-97> | 17419_d86331-1c> |
Optional. list of one or more names of fields in the referenced collection that will render in the autocomplete menu of the control. Defaults to |
multiple 17419_46ccad-0e> |
boolean 17419_2c936b-2d> |
|
Optional. Allow multiple values to be selected 17419_e0a39f-2d> |
min 17419_da99a8-a9> |
number 17419_7ce149-d7> | 17419_9ba3a8-37> |
Optional. Minimum number of items. Ignored if multiple is |
max 17419_a6badf-d9> |
number 17419_a84afc-2b> | 17419_25918b-0c> |
Optional. Maximum number of items. Ignored if multiple is |
options_length 17419_829464-24> |
number 17419_a5e7c2-86> |
|
Optional. Number of options presented to user 17419_1ef920-43> |
Examples
Referencing A Folder Collection
Assuming a separate “authors” collection with “name” and “twitterHandle” fields with subfields “first” and “last” for the “name” field.
name: author
label: Post Author
widget: relation
collection: authors
search_fields: ['name.first', 'twitterHandle']
value_field: name.first
display_fields: ['twitterHandle', 'followerCount']
name: 'author',
label: 'Post Author',
widget: 'relation',
collection: 'authors',
search_fields: ['name.first', 'twitterHandle'],
value_field: 'name.first',
display_fields: ['twitterHandle', 'followerCount'],
The generated UI input will search the authors collection by name and twitterHandle, and display each author’s handle and follower count. On selection, the author’s name is saved for the field.
String Template
Assuming a separate “authors” collection with “name” and “twitterHandle” fields with subfields “first” and “last” for the “name” field.
name: author
label: Post Author
widget: relation
collection: authors
search_fields: ['name.first']
value_field: '{{slug}}'
display_fields: ['{{twitterHandle}} - {{followerCount}}']
name: 'author',
label: 'Post Author',
widget: 'relation',
collection: 'authors',
search_fields: ['name.first'],
value_field: '{{slug}}',
display_fields: ['{{twitterHandle}} - {{followerCount}}'],
The generated UI input will search the authors collection by name, and display each author’s handle and follower count. On selection, the author entry slug is saved for the field.
Referencing A File Collection List Field
Assuming a separate “relation_files” collection with a file named “cities” with a list field “cities” with subfields “name” and “id”.
name: city
label: City
widget: relation
collection: relation_files
file: cities
search_fields: ['cities.*.name']
display_fields: ['cities.*.name']
value_field: 'cities.*.id'
name: 'city',
label: 'City',
widget: 'relation',
collection: 'relation_files',
file: 'cities',
search_fields: ['cities.*.name'],
display_fields: ['cities.*.name'],
value_field: 'cities.*.id',
The generated UI input will search the cities file by city name, and display each city’s name. On selection, the city id is saved for the field.