[bug]: Custom Field requires type: json in schema to save data

オープン
#95 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
full-stack

調査の方向性

Start with the custom-field registration example in /admin/src/index.js and compare it with the official custom-fields documentation linked in the issue. Trace how the registered type and the generated schema affect persistence, then determine whether the fix belongs in the SDK behavior or the documentation. Done means complex custom-field data persists correctly or the required json configuration is clearly documented.

索引モデルが issue の本文から書いたものです。

説明

issue: bug
What version of @strapi/sdk-plugin are you using?
  • Npm version: 10.8.2
  • Node.js version: 20.18.3
  • React version: 18.3.1
  • Strapi version: 5.23.3
  • @strapi/sdk-plugin version: 5.3.2
  • Browser: Chrome
What's Wrong?

When using a custom field from any plugin in a content type schema, if the field is defined as:

"myCustomField": {
  "type": "customField",
  "customField": "plugin::<plugin-name>.<custom-field-name>"
}

Strapi does not save the data unless the field type is changed to "json":

"myCustomField": {
  "type": "json",
  "customField": "plugin::<plugin-name>.<custom-field-name>"
}

This is not documented and causes confusion, since the admin panel recognizes the custom field, but the data is not persisted unless the type is set to json.

To Reproduce
  1. Create a content type with a custom field using a local plugin built with the Strapi SDK (e.g. <plugin-name>), where the custom field is registered as type json in the plugin registration.

  2. Add the custom field from the Content-Type Builder to any collection type.

  3. In the schema, define the field as:

    "myCustomField": {
      "type": "customField",
      "customField": "plugin::<plugin-name>.<custom-field-name>"
    }
    
  4. Go to the admin panel and try to save data using the custom field.

  5. Observe that the data is not saved/persisted.

  6. Change the field type to "json":

    "myCustomField": {
      "type": "json",
      "customField": "plugin::<plugin-name>.<custom-field-name>"
    }
    
  7. Now, data is saved correctly.

Expected Behaviour
Actual Behaviour
  • The admin panel recognizes the custom field and allows input, but Strapi does not persist the data unless the type is set to json.
  • This behaviour is not documented in the official docs, which show examples using type: "customField".
Expected Behaviour
  • Strapi should either:
    • Handle custom fields that store arrays/objects without requiring manual change to "json", or
    • Document this requirement clearly for custom field plugin authors and users.
Technical Comparison with Official Documentation
"color": {
  "type": "customField",
  "customField": "plugin::color-picker.color",
  "options": {
    "format": "hex"
  }
}
  • In practice, for custom fields that store complex data (arrays/objects), the type must be set to json for persistence:
"customFieldExample": {
  "type": "json",
  "customField": "plugin::<plugin-name>.<custom-field-name>"
}
  • If type: "customField" is used, the data is not saved.

Custom Field Registration

File: <plugin-path>/admin/src/index.js

app.customFields.register({
  name: '<custom-field-name>',
  pluginId: '<plugin-name>',
  type: 'json', // Required for metadata persistence
  intlLabel: {
    id: '<plugin-name>.<custom-field-name>.label',
    defaultMessage: '<custom-field-name>',
  },
  intlDescription: {
    id: '<plugin-name>.<custom-field-name>.description',
    defaultMessage: 'Select any asset',
  },
  components: {
    Input: async () =>
      import('./components/Input/Input').then((module) => ({
        default: module.Input,
      })),
  },
  options: {
    // declare options here
  },
});
  • The custom field must use type: 'json' for Strapi to persist complex data (arrays/objects).
  • If type: 'customField' is used, data is not saved.
主要言語
TypeScript
スター
24
フォーク
13
平均マージ
5日 3時間
マージ済み PR(30日)
5

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

strapi/sdk-plugin のほかの issue

strapi/sdk-plugin の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。