defaultValue for Blocks?

default discord avatar
Derosul
7 months ago
10

Hi there, I'm currently using blocks for a collection type, and I want to add a default value to the Block field so my editors have a default setup to work with.



I already tried something like this:



   defaultValue: [
                {
                  blockType: 'registered-block1'
                },
                {
                  blockType: 'registered-block2'
                },
                {
                  blockType: 'registered-block3'
                }
              ]


But that didn't work :l



Managed to fix it, the default value entries requires a

blockName

as well to work.



For future reference, or anyone else looking for this. the payloadCMS repository has a

test

folder including several setups for Payload.



I managed to find a working example here:

https://github.com/payloadcms/payload/blob/master/test/fields/collections/Blocks/index.ts
  • default discord avatar
    Jarrod
    7 months ago

    Hey @Derosul are you using typescript? I would imagine it would have complained that you did not give a block name?

  • default discord avatar
    Derosul
    7 months ago

    Yes, I am using typescript 🙂





    DefaultValue is unknown

    Screenshot_2023-04-26_at_13.47.55.png
  • default discord avatar
    Jarrod
    7 months ago

    Interesting! Yep, figured it was the defaultValue. Hmmm I’ll bring this up internally, I imagine we could improve this!

  • default discord avatar
    Derosul
    7 months ago

    Yes, adding typings should fix questions when it comes to this! in the meantime, using the "test" directory on the payload CMS repo is really helpful when figuring out configs!



    Thanks for checking @Jarrod 🙂

  • default discord avatar
    Jarrod
    7 months ago

    Yeah that’s a gold mine for sure haha!

Open the post
Continue the discussion in Discord
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.