# Smart-action collection

**URL:** <https://community.forestadmin.com/t/smart-action-collection/7404>\
**Category:** Help me!\
**Tags:** smart-action\
**Created:** [August 21, 2024, 1:38pm UTC](https://community.forestadmin.com/t/smart-action-collection/7404 "2024-08-21T13:38:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [August 21, 2024, 2:30pm UTC](https://community.forestadmin.com/t/smart-action-collection/7404/2 "2024-08-21T14:30:03Z")

</div>

Hello @nike1v,

I suppose this is a follow up to the [previous discussion](https://community.forestadmin.com/t/hooks-for-nodejs-smart-actions/7368) we had about dynamic forms.  
I tried to implement something in the way you have described, it is rudimentary but it seems to work fine.

Adding and removing elements from the list updates the form as expected:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/7/7a76a3a2925accabc236d1fb6b987a57c658f131.png)  
=\>  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/cdb0cee1973e5923997c098aba43ada1a22c7030.png)

Here is the snippet for the action:

```javascript
        .addAction("Dynamic form", {
          scope: "Single",
          form: (context) => {
            const form = [
              {
                label: "Orders",
                type: "NumberList",
                widget: "Dropdown",
                isRequired: true,
                options: async (actionContext) => {
                  const orders = await actionContext.dataSource
                    .getCollection("orders")
                    .list({}, ["id"]);

                  return orders.map(({ id }) => id);
                },
              },
            ];

            if (context.formValues['Orders'] && context.formValues['Orders'].length > 0) {
              context.formValues['Orders'].forEach(order => {
                form.push({
                  label: `Check this for order#${order}`,
                  type: 'Boolean',
                  widget: 'Checkbox',
                })
              })
            } 

            return form;
          },
          execute: async (context, resultBuilder) => {
            ...
          },
        })

```

---

_[View the full topic](https://community.forestadmin.com/t/smart-action-collection/7404)._
