Skip to main content
We’ve just introduced Smart actions: they’re great because you can execute virtually any business logic. However, there is one big part missing: how do you let your users provide more information or have interaction when they trigger the Smart action? In short, you need to open a Smart Action Form.

Opening a Smart Action Form

Very often, you will need to ask user inputs before triggering the logic behind a Smart Action.
For example, you might want to specify a reason if you want to block a user account. Or set the amount to charge a user’s credit card.
On our Live Demo example, we’ve defined 4 input fields on the Smart Action Upload Legal Docs on the collection companies.

Handling input values

Here is the list of available options to customize your input form.
The widget property is only partially supported. If you want to use a custom widget via a Smart Action Hook, you’ll need to use the syntax mentioned in the next section.

Use components to better layout your form

This feature is only available from version 9.4.0 (forest-express-sequelize and forest-express-mongoose) / version 9.4.0 (forest-rails) .
you must define your layout in a load hook at minima, and repeat it in each change hook.
This feature is useful when dealing with long/complex forms, with many fields. It will let you organize them and add useful information to guide the end user. The layout must contain the fields as they should be rendered on the form.

List of supported layout components

Node.js

Example

Here’s an example of an action form with many fields, that we want to improve with some layout components, to make it easier for the end user to fill in.

Node.js

Prefill a form with default values

Forest allows you to set default values of your form. In this example, we will prefill the form with data coming from the record itself (1), with just a few extra lines of code.

Making a field read-only

To make a field read only, you can use the isReadOnly property: Combined with the load hook feature, this can be used to make a field read-only dynamically:

Change your form’s data based on previous field values

This feature is only available from version 8.0.0 (forest-express-sequelize and forest-express-mongoose) / version 7.0.0 (forest-rails) .
Here’s a typical example: Selecting a City within a list of cities from the Country you just selected. Then selecting a Zip code within a list of zip codes located in the City you just selected.

How does it work?

The hooks property receives a context object containing:
  • the fields array in its current state (containing also the current values)
  • the request object containing all the information related to the records selection. Explained here.
  • the changedField is the current field who trigger the hook (only for change hook)
fields must be returned. Note that fields is an array containing existing fields with properties described in this section.
If you want to use a widget inside of a hook, you’ll need to use the following syntax on your field:
  • For a text area, use { widgetEdit: 'text area editor', parameters: {} }
  • For a boolean, use { widgetEdit: 'boolean editor', parameters: {} }
  • For a date or a dateonly, use { widgetEdit: 'date editor', parameters: {} }
  • For a file, use { widgetEdit: 'file picker', parameters: {} }
To dynamically change a property within a load or change hook, just set it! For instance, setting a new description for the field city:

Add/remove fields dynamically

This feature is only available from version 8.0.0 (forest-express-sequelize and forest-express-mongoose) / version 7.0.0 (forest-rails).
You can add a field dynamically inside the fields array, like so:

Get selected records with bulk action

When using hooks with a bulk Smart action, you’ll probably need te get the values or ids of the selected records. See below how this can be achieved.