Troubleshooting a warning in Sanity schema for background color field
9 replies
Last updated: Feb 21, 2023
E
Hello dear experts 🙂I’ve got the following in my schema, which I’ve based of the example
in the string docs .
But I get a warning in studio saying “expected type string, got array”. How do I go about fixing that?
in the string docs .
{ name: 'bgColor', title: 'Background colour', type: 'string', options: { list: [ { title: 'Hot pink', value: '#f900c2' }, { title: 'Burnt orange', value: '#f07a54' }, { title: 'Black', value: 'rgb(8,6,6)' }, { title: 'Dark blue', value: 'rgb(32, 32, 100)' }, { title: 'Bright yellow', value: '#EFE600' }, ], layout: 'radio' } }
Feb 21, 2023, 1:16 PM
R
Your code looks good from what I can see. Can you most the object or doc that field is in as well?
Something like:
Something like:
{ title: 'Screening', name: 'screening', type: 'document', fields: [ // ... { title: 'Cinema address', name: 'address', type: 'address' } // ... ] }
Feb 21, 2023, 1:19 PM
E
user C
sorry, I didn’t quite get what you meant there..?Here’s the schema in its entirety, everything else works.import { BsPlayCircle } from 'react-icons/bs' export default { name: 'video', type: 'document', title: 'Video', icon: BsPlayCircle, groups: [ { name: 'content', title: 'Content' }, { name: 'style', title: 'CSS' } ], fieldsets: [ { title: 'Call to action', name: 'cta', description: 'Fill in text and choose page for the call to action button.', group: 'content' } ], fields: [ { name: 'subheading', type: 'string', title: 'Subheading', description: 'Usually the name of the speaker', group: 'content' }, { name: 'title', type: 'string', title: 'Title', description: 'A short, informative title', group: 'content' }, { name: 'text', type: 'bodyPortableText', title: 'Description', description: 'Help the reader understand if the talk is relevant for them', group: 'content' }, { name: 'ctaText', type: 'string', title: 'Call to action text', description: 'The text that goes on the button', fieldset: 'cta' }, { title: 'Link', description: 'Select the talk to link to', name: 'link', type: 'reference', to: [ { type: 'talk' } ], fieldset: 'cta' }, { name: 'image', type: 'mainImage', title: 'Image', group: 'content' }, { name: 'bgColor', title: 'Background colour', type: 'string', options: { list: [ { title: 'Hot pink', value: '#f900c2' }, { title: 'Burnt orange', value: '#f07a54' }, { title: 'Black', value: 'rgb(8,6,6)' }, { title: 'Dark blue', value: 'rgb(32, 32, 100)' }, { title: 'Bright yellow', value: '#EFE600' }, ], layout: 'radio' }, group: 'style' }, { name: 'crop', title: 'Cropping path', type: 'string', group: 'style' }, { name: 'align', title: 'Place the image to the left side', description: 'Right is the default', type: 'boolean', group: 'style' }, { name: 'borderRadius', title: 'Border radius', type: 'string', group: 'style' } ], preview: { select: { title: 'title', media: 'image' } } }
Feb 21, 2023, 1:52 PM
R
I just ran it on a V3 install and everything worked great. (see screenshot) I recommend deleting the doc with the error and starting on a fresh doc to see if the error repeats.
** I had to remove the objects and references that had to do with your other schema.
** I had to remove the objects and references that had to do with your other schema.
Feb 21, 2023, 2:09 PM
E
Thank you, i’ll give that a go!
Feb 21, 2023, 2:09 PM
R
Great! Let me know if it still errors.I also had it setup as a .ts file with defineType & defineFields
Feb 21, 2023, 2:10 PM
E
ok, i don’t know typescript properly yet, so will see how it goes 🙂It might be that it’s kinda stuck, because the field was an array at first, then i changed it to string.
Feb 21, 2023, 2:11 PM
E
that worked ! weird.
Feb 21, 2023, 2:47 PM
R
Your array first then field assumption is correct. I had that happen yesterday with a content block. Glad it worked!
Feb 21, 2023, 2:51 PM
E
Lucky for me it happened to you yesterday. Thank you!
Feb 21, 2023, 2:52 PM
Sanity.io – build remarkable experiences at scale
Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.