addAction with Hook

Hello,

I’m trying to use hooks on Smart Actions. I’m using addAction on CollectionCustomizer, but the ActionDefinition does not contains hooks fields in Typescript.
There is a form field, but no fields as described here : https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions/use-a-smart-action-form#handling-input-values

Is there something that I missed ?

Regards,

David

Hello @dscreve

Welcome to the Forest community !

The documentation you posted is on the previous agent.

The documentation you are looking for, for the new agent is right here

Regards,
Nicolas

2 Likes

Thanks a lot ! That’s perfect !

1 Like

Is there anyway to populate enum from database query (in another collection) ?

You can check this example to see how to populate enum values.

From the context you can get any collection from the same datasource.

You can find the documentation related to the querying through Forest Admin Query Interface

Here is a small example:

 .addAction("Action with populated enum", {
      scope: "Single",
      form: [
        {
          label: "Users email",
          type: "Enum",
          enumValues: async (context) => {
            // Get the collection you want to query
            const usersCollection = context.dataSource.getCollection("users");

            // query the collection
            const users = await usersCollection.list(
              {
                conditionTree: {
                  conditions: [{ field: "id", operator: "LessThan", value: 3 }],
                  aggregator: "And",
                },
              },
              ["email"]
            );

            // return an array with your enum values
            return users.map((u) => u.email);
          },
        },
      ],
}

Thanks : it works fine !

1 Like