Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

defaultValue for Blocks?

default discord avatar
derosul2 years ago
7

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
  • discord user avatar
    jarrod_not_jared
    2 years ago

    Hey

    @203164998514638848

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

  • default discord avatar
    derosul2 years ago

    Yes, I am using typescript 🙂





    DefaultValue is unknown

  • discord user avatar
    jarrod_not_jared
    2 years ago

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

  • default discord avatar
    derosul2 years 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

    @281120856527077378

    🙂

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Yeah that’s a gold mine for sure haha!

  • default discord avatar
    dangerous05last year

    can we use default values for fields that have type UI

  • Ui fields don’t actually store a value so I’m not sure I understand the question

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.