Geoff Ball
Support Engineer at Sanity.io
Geoff is located at Alberta, Canada
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
Sometimes, 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 documentsIf you want to pass a parameter to a query that might not always be defined
Go to Handle Certain Values To Be True