UID field does not automatically generate the slug from the attached field

System Information
  • Strapi Version: 5.0.0

Hi,
I’m using Strapi v5 and in a collection (products) and I’m trying to automatically generate the slug.
If I don’t set the field as required, the slug is not populated.
However, if I set it as required, when I create a new entry, it uses the name of the collection.
Since I want to make the field mandatory and non-editable, this becomes a major issue because it always generates a slug with the value ‘products’ instead of the attached-field.
Here is the schema of my collection:

{
  "kind": "collectionType",
  "collectionName": "products",
  "info": {
    "singularName": "product",
    "pluralName": "products",
    "displayName": "Products",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {
    "i18n": {
      "localized": true
    }
  },
  "attributes": {
    "seo": {
      "type": "component",
      "repeatable": false,
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "component": "base.seo"
    },
    "components": {
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "type": "dynamiczone",
      "components": [
        "composed.hero",
        "composed.banner-full-width-assistance",
        "composed.product-card"
      ]
    },
    "previewTitle": {
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "type": "string",
      "required": true
    },
    "previewAbstract": {
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "type": "text"
    },
    "previewImage": {
      "type": "media",
      "multiple": false,
      "required": true,
      "allowedTypes": [
        "images",
        "files"
      ],
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      }
    },
    "altPreviewImage": {
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "type": "string"
    },
    "slug": {
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "type": "uid",
      "targetField": "previewTitle",
      "required": true
    }
  }
}

Thanks in advance.

1 Like

Hello i’ve same problem; any news about?

1 Like

We solved with custom code inside js using strapi document middleware instead lifecycles.

Maybe in actual docs there is the need to clarify the usage of actual lifecycles.js in model.