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

Issue with setting initial value of a string input in Sanity.io studio.

2 replies
Last updated: Aug 7, 2023
Hi All, I'm currently trying to set the
initialValue
of a string input, following the official Sanity documentation . I copied one of the examples and it doesn't seem to be working in my studio (I'm expecting the value of
InitialValue
to appear in the text input field). To provide additional context, I'm trying to add this field to an existing document, maybe that what's causing the issue.
Please let me know if there's anything I'm doing wrong and thank you in advance.

schema:

export default {
  name: 'info',
  title: 'Information',
  type: 'document',
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
      initialValue: 'Hello World',
    },
  ],
}
I also tried the following option, which didn't work either:

export default {
  name: 'info',
  title: 'Information',
  type: 'document',
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
    },
  ],
  initialValue: {
    title: 'Hello World',
  },
}
studio:
Aug 7, 2023, 10:14 AM
You should be able to see the initial value when you create a new document of the type after you introduced the
initialValue
field. If you are testing with a document that was created before you introduced that field, it may not work.
Aug 7, 2023, 12:56 PM
Thank you for letting me know, that's what I suspected. The
initialValue
does indeed show when creating a new document.
Aug 7, 2023, 1:09 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?