๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

OneOf Option for Single Entry Field

4 replies
Last updated: Jul 26, 2022
Hi all. I was just thinking of something: while an
field has an option
to list all possible types to insert (either embed or reference), AFAIK there's no equivalent for a single entry field. For example, type
. 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
  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?