Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/fields/text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,17 @@ export const ExampleCollection: CollectionConfig = {

The slug field exposes a few top-level config options for easy customization:

| Option | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | To be used as the slug field's name. Defaults to `slug`. |
| `overrides` | A function that receives the default fields so you can override on a granular level. See example below. [More details](#slug-overrides). |
| `checkboxName` | To be used as the name for the `generateSlug` checkbox field. Defaults to `generateSlug`. |
| `useAsSlug` | The name of the top-level field to use when generating the slug. This field must exist in the same collection. Defaults to `title`. |
| `localized` | Enable localization on the `slug` and `generateSlug` fields. Defaults to `false`. |
| `position` | The position of the slug field. [More details](./overview#admin-options). |
| `required` | Require the slug field. Defaults to `true`. |
| `slugify` | Override the default slugify function. [More details](#custom-slugify-function). |
| Option | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | To be used as the slug field's name. Defaults to `slug`. |
| `overrides` | A function that receives the default fields so you can override on a granular level. See example below. [More details](#slug-overrides). |
| `checkboxName` | To be used as the name for the `generateSlug` checkbox field. Defaults to `generateSlug`. |
| `disableUnique` | Disables the unique index on the field. Useful when you want to add a compound unique index to the collection `indexes` config instead, for example with the multi-tenant plugin where the slug is only unique per tenant, not globally |
| `useAsSlug` | The name of the top-level field to use when generating the slug. This field must exist in the same collection. Defaults to `title`. |
| `localized` | Enable localization on the `slug` and `generateSlug` fields. Defaults to `false`. |
| `position` | The position of the slug field. [More details](./overview#admin-options). |
| `required` | Require the slug field. Defaults to `true`. |
| `slugify` | Override the default slugify function. [More details](#custom-slugify-function). |

### Slug Overrides

Expand Down
10 changes: 9 additions & 1 deletion packages/payload/src/fields/baseFields/slug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export type SlugFieldArgs = {
* @default 'generateSlug'
*/
checkboxName?: string
/**
* Disables the unique index on the field.
* This is useful if instead, you want to add a compound unique index to the collection `indexes` config,
* for example with the multi tenant plugin, where the slug is only unique per tenant, not globally.
* @default false
*/
disableUnique?: boolean
/**
* @deprecated use `useAsSlug` instead.
*/
Expand Down Expand Up @@ -88,6 +95,7 @@ export type SlugFieldClientProps = SlugFieldClientPropsOnly & TextFieldClientPro
export const slugField: SlugField = ({
name: slugFieldName = 'slug',
checkboxName = 'generateSlug',
disableUnique = false,
fieldToUse,
localized,
overrides,
Expand Down Expand Up @@ -145,7 +153,7 @@ export const slugField: SlugField = ({
index: true,
localized,
required,
unique: true,
unique: !disableUnique,
},
],
}
Expand Down
Loading