Validation Error: Validator for flag "uri" not found for type "Object"`
6 replies
Last updated: Aug 6, 2020
K
i get an odd error after I added validation to an url field in my schema within a `block`…
to url field was not accepting
to this field. when setting a link to a
is there something I am missing here?
to url field was not accepting
<mailto:mail@example.com>so I added
validation: Rule => Rule.uri({ scheme: ['http', 'https', 'mailto', 'tel'] })
mailto:url it never validates and throws an Error:
Error: pageContent[_key=="59a60b5078e7"].copy[_key=="2383b6a1ee99"]: Error validating value: Validator for flag "uri" not found for type "Object"
is there something I am missing here?
Aug 6, 2020, 8:33 AM
P
Could you share your code for where exactly you include the validation? Is it in inside your
urltype field?
Aug 6, 2020, 9:32 AM
K
this is the complete schema for the object I create to have “page builder” -like approach
import linkIcon from 'react-icons/lib/fa/paperclip'; import moduleSettings from '../common/moduleSettings'; import icon from '../../assets/ModuleTextCentered'; export default { title: 'Text zentriert', name: 'moduleTextCentered', type: 'object', icon, fields: [ { title: 'Titel', name: 'title', type: 'string', }, { title: 'Subtitel', name: 'subTitle', type: 'string', }, { title: 'Text', name: 'copy', type: 'array', of: [ { type: 'block', marks: { annotations: [ { name: 'link', type: 'object', title: 'Link', fields: [ { title: 'URL', name: 'url', type: 'url', }, ], validation: Rule => Rule.uri({ scheme: ['http', 'https', 'mailto', 'tel'], }), }, { name: 'internalLink', type: 'object', title: 'Internal link', blockEditor: { icon: linkIcon, }, fields: [ { name: 'reference', type: 'reference', to: [ { type: 'page' }, // other types you may want to link to ], }, ], }, ], }, }, ], }, { title: 'Button', name: 'button', type: 'internalLinkButton', description: 'optionaler Link auf eine interne Seite', }, ...moduleSettings, ], };
Aug 6, 2020, 9:35 AM
P
The issue here seems to be that the validation is set for the
linkobject instead of the
url, so the
urivalidator flag is not available. Have you tried moving the validation to the
urltype instead, as follows?
{ title: 'URL', name: 'url', type: 'url', validation: Rule => Rule.uri({ scheme: ['http', 'https', 'mailto', 'tel'], }), },
Aug 6, 2020, 10:24 AM
K
doh
Aug 6, 2020, 10:29 AM
K
thanks… that solved it
Aug 6, 2020, 10:29 AM
P
It’s really easy to miss in nested structures 🙂 glad it’s working!
Aug 6, 2020, 10:34 AM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.