How to add default value for blocks

default discord avatar
Stupidism
10 months ago
1 1

I have a content field requires at least 1 block.
image

I want to save our editors' effort by providing a default value for it, but defaultValue is not working as I expected.

  • default discord avatar
    Stupidism
    10 months ago

    Found the answer myself.

    
                {
                  name: 'content',
                  label: false,
                  type: 'blocks',
                  minRows: 1,
                  maxRows: 1,
                  blocks: [
                      {
                        slug: 'content',
                        labels: {
                          singular: 'Content',
                          plural: 'Content Blocks',
                        },
                        fields: [
                          {
                            name: 'richText',
                            type: 'richText',
                          }
                        ]
                      }
                  ],
                  defaultValue: [
                    {
                      richText: [{ children: [{ text: '' }] }],
                      blockType: 'content',
                    },
                  ],
                },
    

    It's really interesting that writing/asking the question itself can give me the answer.

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.