Geoff Ball
Support Engineer at Sanity.io
Validate a field only if a sibling boolean type is set to true.
export default {
name: "docName",
title: "Document Name",
type: "document",
fields: [
{
name: 'flag',
title: 'Flag for Validation',
type: 'boolean',
},
{
name: 'entry',
type: 'string',
title: 'Entry',
validation: Rule => Rule.custom((field, context) => (context.document.flag && field === undefined) ? "This field must not be empty." : true),
},
],
};
There may be cases where a field should only be validated when flagged. This short snippet will require a non-empty field entry
only when flag
is set to true.
If flag
is set to false, entry
will not be validated (i.e., the string can be empty).
Support Engineer at Sanity.io
This snippet can be used to fetch current, previous and next articles based on publication date and related tags.
Go to Get current, previous and next post, filtered by tagsIf you'd like to be able to reference your project users within your content, you'll need to create a document for them.
Go to Create A Document for All Current Project UsersScript to batch remove a field from all documents that match a GROQ query
Go to Batch remove a fieldA custom input component that lets the schema creator control max, min, and step values on a number input.
Go to Controlled Number Custom Input Component