How to Manage Data with a New Field (Component) in the Admin Panel

System Information
  • Strapi Version: 4.3.4
  • Operating System: macOS
  • Database: PostgreSQL
  • Node Version: 14.20.0
  • NPM Version: 6.14.17
  • Yarn Version: 1.22.19

How do you write model/database changes for a custom field/component?

Similar to Field Registering - Strapi Developer Docs, I’ve created a new field/component in the admin panel but that’s where it stops, it doesn’t create a new field in the database table.

The field is working properly in the UI, I can see the data before an update. I created a lifecyles.ts file in my content-type and can see the value before and of course, it doesn’t show it after.

export default {
  beforeUpdate: (event) => {
    console.log(event.params.data.foo); // Outputs test
  },

  afterUpdate: (event) => {
    console.log(event.result.foo); // Outputs undefined
  }
};

I’ve managed to solve this problem after poking around the source code, I’ll reply here with a solution in the near future (unfortunately I’m working on a deadline atm).

Ping me to reply if I haven’t when you read this message :slight_smile:

Hey, can you please reply how can I add custom logic to fetch data for content creation.

Hey @dallasclark, I would like to know your solution for this. Thx

No worries, I’ll post something soon with a GitHub Repository to demo with

Hey @Yashpal_Chhajer / @Dupflo,

I wrote the above article over the weekend, please let me know how you go and I welcome any feedback.

1 Like