Initial value not applied when editing existing documents in Sanity

2 replies
Last updated: Oct 20, 2024
Puzzled on how to set
intialValue
for a field. Docs seem pretty straightforward but when I use the example similar to
export default {
  name: 'project',
  type: 'document',
  title: 'Project',
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
      initialValue: 'This string'
    },
It does not fill in the filed with the initial value, nothing happens at all, no error in the console or anything. What am I missing? example taken from
here
Oct 19, 2024, 4:11 PM
Are you creating a new document to test it? Initial values are only applied when you initially create the document (or create the object, in the case of array items).
Existing documents won't get the initial value applied.
Oct 19, 2024, 4:29 PM
Oh jeez, you know that got me once before a while back and as soon as I saw your response I knew it. Yep that was it, I was just refreshing that page. Thanks for the reminder 🤦
Oct 20, 2024, 3:10 PM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?