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.

Duplicating a collection item

default discord avatar
raoulyounglast year
2

i am using beforeValidate to create a unique slug when a new post is created. it works just fine as it is now


The problem i find is that if i try to duplicate the field in the adminUI it wont work anymore.


I am wondering how i can get in between what ever the duplicate button does?



hooks: {


beforeValidate: [


async ({ data, value }) => {


return await creatuSlug(


data,


value,


data.postName,


"posts"


);


},


],


},



The beforeDuplicate hook is an async function that accepts an object containing the data to duplicate, as well as the locale of the doc to duplicate. Within this hook, you can modify the data to be duplicated, which is useful in cases where you have unique fields that need to be incremented or similar, as well as if you want to automatically modify a document's title.

  • @1117749311757881464

    sounds like you are all set, right?

  • default discord avatar
    raoulyounglast year

    i think i am 🙂



    @281120856527077378

    I got back to this now, seems that i am stuck after all, can't seem to get in between the duplication process.

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.