Skip to content

Issue storing data from Custom Fields in v4.x #12145

@nefarioustim

Description

@nefarioustim

Bug report

Describe the bug

In Strapi 3 it is possible to declare a custom field within a content-type schema and have it link to a custom component for data entry using what is essentially undocumented functionality. In order to do this, we need to update the attributes within schema.json to include a columnType like so:

  "attributes": {
    "Title": {
      "type": "string",
      "required": true
    },
    "Video Stream": {
      "type": "videostream",
      "columnType": "text"
    }
  }

This allows the component attached to the videostream type to store data in a DB column matching columnType.

In Strapi 3, we are still able to attach a custom component to a custom field, using the addFields method within the register method of a plugin:

app.addFields({ type: "videostream", Component: VideoStream });

However, adding the columnType to schema.json no longer creates the relevant column in the DB table for a content type, which means a custom field can no longer store or retrieve data for said content type. I suspect this is due to the addition of Yup schema validation under the hood.

Steps to reproduce the behavior

  1. Add a custom field via a plugin, using app.addFields() within the register(app) method.
  2. Reference the custom field in the attributes section in schema.json for a content type.
  3. The custom component will be rendered for the field in the content manager.
  4. When data is saved or attempted to load from an existing entry, it will fail.

Expected behavior

There should be some method to allow storage as a standard DB-ready data type.

In my case, I simply want to save a UUID from a custom menu drop-down that renders thumbnails for a list of video streams.

I appreciate this is essentially an undocumented feature, but it has broken a large number of plugins developed within the community. This includes the Color Picker plugin tutorial that is often referenced for documentation: https://www.paulgaumer.com/blog/how-to-create-a-color-picker-plugin-for-strapi-cms

Am happy to work on a PR to fix the issue if someone can give me some pointers around the integration of Yup and how the creation of DB tables works during startup.

System

  • Node.js version: v16
  • Yarn version: Classic
  • Strapi version: v4.0.3
  • Database: MySQL
  • Operating system: Docker hosted Alpine linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: help wantedseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions