✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Issue with setting `initialValue` containing `/` in a schema field.

3 replies
Last updated: Aug 21, 2023
Hey there Sanity people! I have a schema that takes in a list of values to select from which looks like the following:
const media = {
  size: [
    {
      title: '1/4',
      value: '1/4'
    },
    {
      title: '1/2',
      value: '1/2'
    },
    {
      title: '3/4',
      value: '3/4'
    },
    {
      title: '1/1',
      value: 'full'
    }
  ]
}
Then pass it in to my schema's field such as this:

{
  title: 'Media Size',
  name: 'mediaSize',
  type: 'string',
  description: 'Controls the size of the media in relation to the display grid',
  validation: (rule) => rule.required(),
  options: {
    list: media.size,
  },
  initialValue: 'full',
}
I notice if I use
initialValue
and set that value to one that contains a
/
it does not work. So should I change the names of the values to pure text (with no
/
or
-
)?
Aug 21, 2023, 7:02 PM
Looks like it’s working for me. What version of the Studio are you on? Can you share what your code looks like when you use something with a
/
as the initial value?
Aug 21, 2023, 7:25 PM
user M
You know what its working for me now.. lol. I think the issue was that it didn't populate already existing "media objects" I have, but when I create a new one now its working and the
initialValue
is set to what its suppose to be. Sorry for the hassle 😖
Aug 21, 2023, 8:29 PM
No hassle at all!
Aug 21, 2023, 8:35 PM

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.

Was this answer helpful?