payload-better-fields-plugin
payload-better-fields-plugin copied to clipboard
Slug appends '-1' on creation of new item
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:
- Have a collection with a slugfield similar to the one displayed above
- Create a new document in the collection, give it a name that's not been used before
- 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,
}
Can confirm!