Field API don't work as expected

System Information
  • Strapi Version: 3.5.4
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I’m find this tutorial : " How to create a Color Picker plugin for Strapi CMS" and try to repeat it

In tutorial new ColorPicker type was created and then it used in Strapi.

Short descripton:

  1. create plugin
  2. call
    strapi.registerField({ type: "colorpicker", Component: ColorPicker });
  1. in component ColorPicker you must support value and onChange props.
    onChange function send to Strapi result of editing

  2. In model collection specify additional field like:
    for example in file:
    api/testfld/models/testfld.settings.json
    add to attributes new field type and specify standart database type:

 "color": {
      "type": "colorpicker",
      "columnType": "string"
    }

Result: I see and can change values of colorpicker type in content manager, and after save - I can see my color value in database.

Problem : after I’m save data in edit form, return to Tesflds list and click record to edit - initial value don’t pass to custom field.

Let’s see: I’m made two custom field:
strapi.registerField({ type: “colorpicker”, Component: ColorPicker });
strapi.registerField({ type: “bool”, Component: Toggle });

One - replace standart bool type, second - colorpicker type.
In component I’m write props.value to console.log
In picture - you can see that bool component recieved inititial value prop - but colorpicker don’t recieve initial value prop and that’s why editing of colorpicker is imposiible - but after edit - it save it’s value to database.

How is possible to pass value, readed from database to custom field component ?
5 month ago Paul can run it - bu I’m can’t.

My github is:

1 Like

Problem was solved :slight_smile:
What’s happend:
Paul made mistake in ColorPicker component
It hase props.value and internal color variable where color must be equal value at first run.

Paul assign color=value only at first components initialization.

But props.value changed several time by internal strapi and Paul don’t initialize internal color variable on next call

I’m publish correct component - and all work as expexted !

My working git in branch master:

2 Likes