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.
- Rails
- Django
- Laravel
On our Live Demo example, we’ve defined 4 input fields on the Smart Action
Upload Legal Docs on the collection Company.
Handling input values
Here is the list of available options to customize your input form.| Name | Type | Description |
|---|---|---|
| field | string | Label of the input field. |
| type | string or array | Type of your field.
|
| reference | string | (optional) Specify that the input is a reference to another collection. You must specify the primary key (ex: category.id). |
| enums | array of strings | (optional) Required only for the Enum type. This is where you list all the possible values for your input field. |
| description | string | (optional) Add a description for your admin users to help them fill correctly your form |
| isRequired | boolean | (optional) If true, your input field will be set as required in the browser. Default is false. |
| hook | string | (optional) Specify the change hook. If specified the corresponding hook is called when the input change |
| widget | string | (optional) The following widgets are available to your smart action fields (text area, date, boolean, file, dateonly) |
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) .List of supported layout components
Ruby on Rails
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.Ruby on Rails

Making a form dynamic with hooks
Business logic often requires your forms to adapt to its context. Forest makes this possible through a powerful way to extend your form’s logic. To make Smart Action Forms dynamic, we’ve introduced the concept of hooks: hooks allow you to run some logic upon a specific event. Theload hook is called when the form loads, allowing you to change its properties upon load.
The change hook is called whenever you interact with a field of the form.
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 theisReadOnly property:
| Name | Type | Description |
|---|---|---|
isReadOnly | boolean | (optional) If true, the Smart action field won’t be editable in the form. Default is false |
How does it work?
Thehooks property receives a context object containing:
- the
fieldsarray in its current state (containing also the current values) - the
requestobject containing all the information related to the records selection. Explained here. - the
changedFieldis 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.load or change hook, just set it! For instance, setting a new description for the field city:
We added the
changedField attribute so that you can easily know what changed.change hook on a dynamically-added field. Simply use the following syntax: