OptionalactionsOptionalcreationWhether to allow creation of new references. default: true
If false, it will only be possible to link to existing documents, if the onLinkDocument callback is provided.
If true, it will be possible to create new references to any template of the type.
If an array is provided, it will only be possible to create new references that match the template id in the array provided.
To define how a creation will be handled, you can use the initialValue option in the
document type that will be linked.
For example:
I want to create a new book from an author:
In the author we will have the
Then in the book type, we will have the initialValue option to define the default values for the new book.
This initialValue callback will receive the reference object that needs to be linked to the book in the params.
// Book type
export default {
type: 'document',
name: 'book',
title: 'Book',
fields: [
{
name: 'author',
type: 'reference',
to: [{type: 'author'}],
},
],
initialValue: (params) => {
return {
author: params?.reference,
}
}
OptionaldescriptionOptionalfilterThe filter query to apply to the incoming references in addition to the type filter.
For example: filter all books that are from an specific editorial brand: editorialBrand == "Random House"
The _type filter is applied automatically.
OptionalfilterOptionalonCallback to link a document to a reference.
This function is called when a user wants to link an existing document to the current document. It receives two parameters:
The developer must implement this function to define where and how the reference should be placed within the document structure. The function should return the modified document with the reference properly added.
For example:
onLinkDocument: (document, reference) => {
return {
...document,
author: reference,
}
}
The document to link to the reference.
The reference to link to the document.
The document to link to the reference. If false, the document will not be linked to the reference.
OptionaltitleThe type of the incoming references.
Callback to define the actions that will be shown for the incoming reference document.
For example: