Hide/filter document types in reference field "Create New" option
Yes! You can control which document types appear in the "Create new" option for reference fields using the newDocumentOptions configuration in your Sanity Studio.
While there isn't a built-in disableNew per-type option directly on the reference field, you can use the global newDocumentOptions function in your Studio configuration to filter out specific document types based on context. This function receives information about where the creation is being triggered from, including reference field context.
Here's how you can implement this:
// sanity.config.ts
import {defineConfig} from 'sanity'
export default defineConfig({
// ... other config
document: {
newDocumentOptions: (prev, {creationContext}) => {
// If creating from a reference field
if (creationContext.type === 'document' && creationContext.schemaType) {
// Filter out 'product' type when creating from references
return prev.filter(template => template.templateId !== 'product')
}
return prev
}
}
})For more granular control based on which specific reference field is being used, you can check additional properties in the creationContext:
newDocumentOptions: (prev, {creationContext}) => {
// Check if we're in a reference field context
if (creationContext.type === 'document') {
// You can inspect creationContext to determine the parent document type
// and filter accordingly
// Example: Remove product from all reference field creations
return prev.filter(template => template.templateId !== 'product')
}
return prev
}Alternative approach: If you want to completely disable inline creation for specific reference fields, you can use the disableNew option:
{
name: 'relatedItem',
type: 'reference',
to: [{type: 'product'}, {type: 'article'}],
options: {
disableNew: true // Disables "Create new" entirely for this field
}
}This approach gives you control over the creation experience while maintaining the flexibility of your reference field configuration. The newDocumentOptions method is particularly powerful because it can respond to the specific context where document creation is triggered.
Show original thread6 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.