πŸ‘€ See Sanity in action: Watch product demo now β†’

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.io – build remarkable experiences at scale

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

Categorized in