NouanceLabs / payload-better-fields-plugin

This plugin aims to provide you with very specific and improved fields for the Payload admin panel.
MIT License
124 stars 2 forks source link

Slug appends '-1' on creation of new item #74

Open Augigauki opened 3 months ago

Augigauki commented 3 months ago

I'm facing an issue where the slug field saves with an appended '-1' when I create a new document in a collection.

This is my field:

...SlugField(
    {
    name: 'slug',
    admin: {
        width: '50%',
    },
    localized: true,
    },
    {
        useFields: ['name'],
        slugify: { locale: 'nb' },
        appendOnDuplication: true,
    }
)

The issue goes away if I remove appendOnDuplication: true, but then duplicating a document results in an error because the slug field has to be unique across documents.

Steps to reproduce:

  1. Have a collection with a slugfield similar to the one displayed above
  2. Create a new document in the collection, give it a name that's not been used before
  3. Let slug autogenerate from title, don't check the checkbox

Expected result: Document is created with the slug checkbox unchecked and the slug a slugified version of the documents title

Actual result: Document is created, the slug checkbox is checked and the slug is a slugified version of the title with '-1' appended

I have configured my Payload instance for localized content, here is the localization config from my payload.config.ts file:

localization: {
    locales: [
        {
            label: {
                en: 'English',
                nb: 'Engelsk',
                se: 'Engelsk',
            },
            code: 'en',
        },
        {
            label: {
                en: 'Norwegian',
                nb: 'Norsk',
                se: 'Norska',
            },
            code: 'no',
        },
        {
            label: {
                en: 'Swedish',
                nb: 'Svensk',
                se: 'Svenska',
            },
            code: 'se',
        },
    ],
    defaultLocale: 'en',
    fallback: true,
}
carstenblt commented 3 months ago

Can confirm!