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 an item with a unique fileld

default discord avatar
plainnn2 years ago
3

When duplicating a blog post with a unique field (slug in my case) I get the error 'The following field is invalid: slug'



While I understand why this is happening, would it be possible to duplicate an item and then clear the unique field? Allowing the user to duplicate and requiring the unique field to be updated

  • default discord avatar
    exo37182 years ago

    You can use the

    beforeDuplicate

    hook to assign a new unique slug to the document

    https://payloadcms.com/docs/configuration/collections#admin-hooks
  • default discord avatar
    bregnballelast year

    Can I follow up on this question?


    Would it be possible to prompt the user for that unique slug instead of doing it programatically?

  • default discord avatar
    aman_680772 months ago

    hi guys i got this same error



    info:



    Binaries:


    Node: 20.11.1


    npm: 10.2.4


    Yarn: 1.22.22


    pnpm: 10.3.0


    Relevant Packages:


    payload: 3.23.0


    next: 15.1.5


    @payloadcms/db-mongodb: 3.23.0


    @payloadcms/email-nodemailer: 3.23.0


    @payloadcms/graphql: 3.23.0


    @payloadcms/next/utilities: 3.23.0


    @payloadcms/payload-cloud: 3.23.0


    @payloadcms/plugin-cloud-storage: 3.23.0


    @payloadcms/richtext-lexical: 3.23.0


    @payloadcms/storage-azure: 3.23.0


    @payloadcms/translations: 3.23.0


    @payloadcms/ui/shared: 3.23.0


    react: 19.0.0


    react-dom: 19.0.0


    Operating System:


    Platform: darwin


    Arch: x64


    Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:22:00 PST 2025; root:xnu-11215.81.4~3/RELEASE_X86_64


    Available memory (MB): 16384


    Available CPU cores: 16




    error in terminal:



    [TypeError: Invalid state: Controller is already closed] {



      code: 'ERR_INVALID_STATE'



    }





    error in network:



    URL:

    http://localhost:3000/api/pages/67b2e5b7e577104024618dce/duplicate?locale=en

    message: "The following field is invalid: email"



    name: "ValidationError"





    i cant find any reported bug regarding this, can you help me here




    CAN YOU PLEASE HELP ?




    ONLY EMAIL NAMED VALUE IS USED IN src/collections/users.ts



    import type { CollectionConfig } from 'payload'



    export const Users: CollectionConfig = {


    slug: 'users',


    admin: {


    useAsTitle: 'email',


    },


    auth: true,


    fields: [


    // Email added by default


    // Add more fields as needed


    ],


    }

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.