This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
Releases: hdoro/sanity-plugin-conditional-field
Releases · hdoro/sanity-plugin-conditional-field
First and final release
As many asked for a way of using this plugin in nested arrays/objects, I figured it was worthwhile even though an official API is coming. This also fixes #1 with the help of Juan Norris ;)
Breaking changes
Before, you'd define conditional fields with the options.condition
property:
{
name: 'externalUrl',
title: 'URL to the content',
type: 'url',
inputComponent: ConditionalField,
options: {
// DEPRECATED 👇
condition: document => !document.internal
}
},
Now conditionals are defined via the options.hide
property, which receives a new object as its sole argument, containing the document and the fields' parents:
{
name: 'url',
title: 'External URL',
type: 'string',
inputComponent: ConditionalField,
options: {
hide: ({ parents }) => {
// Parents array exposes the closest parents in order
// Hence, parents[0] is the current object's value
return parents[0].external
},
},
},
Please take a look at the docs for how to use this 😉
Just to reinforce, this plugin won't be maintained further an official Sanity APIs for conditional fields is coming.