Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

OneOf Option for Single Entry Field

4 replies
Last updated: Jul 26, 2022
Hi all. I was just thinking of something: while an
array
field has an option
of
to list all possible types to insert (either embed or reference), AFAIK there's no equivalent for a single entry field. For example, type
object
with
oneOf
. Something like this would be very useful to have IMHO:
{
  type: 'object',
  name: 'thing',
  title: 'Thing',
  oneOf: [{ type: 'widget'}, { type: 'tool' }]
}
Jul 21, 2022, 8:05 PM
Like a union type. I would love this.
Jul 21, 2022, 8:27 PM
Maybe ideas-and-feedback? šŸ™‚
Jul 22, 2022, 7:20 AM
Will crosspost there šŸ™‚
Jul 22, 2022, 7:22 AM
You can use a selection of things though with an array and a validation of
maxLength
instead:
{
  type: 'array',
  name: 'thing',
  title: 'Thing',
  of: [{ type: 'widget'}, { type: 'tool' }],
  validation: Rule => Rule.max(1)
}
You can also use
options to do some awesome stuff btw.
Jul 26, 2022, 2:30 PM

Sanityā€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?