payload-better-fields-plugin icon indicating copy to clipboard operation
payload-better-fields-plugin copied to clipboard

Slug appends '-1' on creation of new item

Open Augigauki opened this issue 11 months ago • 1 comments

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,
}

Augigauki avatar Mar 18 '24 10:03 Augigauki

Can confirm!

carstenblt avatar Mar 22 '24 13:03 carstenblt