Field type "Computed"
Steve Chen
Before we get this, you can use life cycles.
Add a lifecycles.js in your class folder with code like this:
module.exports = {
beforeCreate(event) {
grade = event.params.data.grade;
level = event.params.data.level;
event.params.data.class_name =
G${grade} ${level}
;},
beforeUpdate(event) {
grade = event.params.data.grade;
level = event.params.data.level;
event.params.data.class_name =
G${grade} ${level}
;},
};
Florent Catiau-Tristant
Steve Chen To complete your answer, this is what I did in the meantime the feature gets prioritized:
- Create a new field in my entity as usual. Make it required, and possiblyprivateif you don't need it to be returned by the api.
- Add the lifecycle hooks to automatically update its value based on other entity attributes.
- On the Strapi interface, update the "Configuration View" and make that field not editable, so that nobody can manually updates this attribute's value from the UI.
Works like a charm for my use case :)