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
Your block styles will normally look the same in the editor and the styles dropdown. For the times you don't want that, this workaround lets you configure them differently.
Go to Create different block styles for the dropdown and editorSometimes, you just need to migrate a document or two.
Go to Ad hoc document migrationGROQ doesn't yet include a function to match the end of a string, but we can simulate it by splitting our string on our term.
Go to Matching the end of a string in GROQSimplify your Studio experience by hiding deprecated fields when you create new documents.
Go to Hide a deprecated field in new documents