# Smart Action form hooks - Dynamic enums on a referenced collection

**URL:** <https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586>\
**Category:** Help me!\
**Tags:** howtos\
**Created:** [January 8, 2021, 7:36am UTC](https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586 "2021-01-08T07:36:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guillaumejauffret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumejauffret/32/61_2.png) [@guillaumejauffret](https://community.forestadmin.com/u/guillaumejauffret)\
**Post date:** [January 8, 2021, 7:36am UTC](https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586/1 "2021-01-08T07:36:03Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![anon20071947](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@anon20071947](https://community.forestadmin.com/u/anon20071947)\
**Post date:** [January 8, 2021, 12:40pm UTC](https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586/2 "2021-01-08T12:40:09Z")

</div>

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 👇🏼

```javascript
    {
      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 😃

---

<div class="post-metadata">

**Author:** ![guillaumejauffret](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumejauffret/32/61_2.png) [@guillaumejauffret](https://community.forestadmin.com/u/guillaumejauffret)\
**Post date:** [January 11, 2021, 8:33am UTC](https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586/3 "2021-01-11T08:33:21Z")

</div>

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:

```javascript
{
        field: 'Montant',
        disable/isReadOnly: true/false, 
        type: 'Number',
      }

```

---

<div class="post-metadata">

**Author:** ![anon20071947](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@anon20071947](https://community.forestadmin.com/u/anon20071947)\
**Post date:** [January 11, 2021, 9:44am UTC](https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586/4 "2021-01-11T09:44:03Z")

</div>

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 📅

---

<div class="post-metadata">

**Author:** ![anon54865804](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@anon54865804](https://community.forestadmin.com/u/anon54865804)\
**Post date:** [February 17, 2021, 11:17am UTC](https://community.forestadmin.com/t/smart-action-form-hooks-dynamic-enums-on-a-referenced-collection/1586/5 "2021-02-17T11:17:41Z")

</div>

Hi Guillaume  
A workaround to display a read-only field in the form is to make it as a ‘fake’ dropdown

Example:

```javascript
  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;
      },
    },
  }],

```

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/f/f9e4ea17ee55044de4ee33f294df663c78d04975.png)

This is a workaround, but our product & tech teams are working to implement a way to make a field read only
