@ziad
I have tested dynamic enums. It works great for “normal” cases
However, are you able to manage the case when the enum values are references to records in another table/collection? And would it be possible for instance to display a label in the enum list and then get id
of the record as the value linked to the label. Do you see what I mean?
1 Like
Hi there @guillaumejauffret
(I moved your post to a new topic for the community to benefit as well)
Thanks for your feedback on the Smart Action form hooks! For the moment, we don’t support using both the reference
option in the fields declaration and applying filtering on the same field in the hooks.
There’s a workaround however, you can simply comment the reference
option and manage all the filtering logic in the hooks. Here’s an example where a customer hasMany
orders on forest-express-sequelize
{
name: 'Update order status',
type: 'single',
fields: [{
field: 'order',
type: 'Enum',
enums: [],
// reference: 'orders.ref',
}, {
field: 'status',
type: 'Enum',
enums: ['Ready for shipping', 'Being processed', 'In transit', 'Shipped'],
}, {
field: 'Montant',
type: 'Number',
}],
hooks: {
load: async ({ fields, record }) => {
const newFields = fields;
const customerOrders = await orders.findAll({ where: { customerIdKey: record.id } });
const customerOrdersIds = await _.chain(customerOrders).map((element) => _.values(_.pick((element), 'ref'))).flatten().value();
newFields.order.enums = customerOrdersIds;
return newFields;
},
},
},
I will push your request to our productboard, let me know if this works for you in the meantime
2 Likes
hi @anon20071947 ,
thanks, this works for sure.
Moreover, would it be possible to disable a field?
I would like to display some data that should not be modified in the form. It is a way for me to give more details about the record to update. As of now, it’s not really a problem because I just don’t take catch the value of the field in the controller logic of the action but I think it would not be complicated to implement and would add a nice UX feature.
A disable
or isReadOnly
property should make it:
{
field: 'Montant',
disable/isReadOnly: true/false,
type: 'Number',
}
1 Like
Great!
As for the read-only fields in Smart Action forms, this feature is not available yet.
We are working on it this quarter
I’ll let you know when it’s released
2 Likes
Hi Guillaume
A workaround to display a read-only field in the form is to make it as a ‘fake’ dropdown
Example:
actions: [{
name: 'Simple action',
type: 'single',
fields: [{
field: 'Field 1',
type: 'String',
}, {
field: 'Field ReadOnly',
type: 'String',
widget: 'dropdown',
}],
hooks: {
load: ({ fields, record }) => {
fields['Field ReadOnly'].value = 'A read only message';
return fields;
},
},
}],
This is a workaround, but our product & tech teams are working to implement a way to make a field read only