Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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 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?