# Static Forms

{% hint style="success" %}
This is the official documentation of the `@forestadmin/agent` Node.js agent.
{% endhint %}

Very often, you will need to ask for user inputs before triggering the logic behind an 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.

![Action Form displayed on Forest Admin](https://3861847666-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9UN5oBJhgzLadOqi7jx6%2Fuploads%2Fgit-blob-6d3a703ca3e1bb4f3d67c8ae1c4a907fbf2711e6%2Factions-forms-charge-cc.png?alt=media)

## Field Configuration

{% hint style="info" %}
More information about the `ActionField` type can be found on our [API Reference](https://forestadmin.github.io/agent-nodejs/types/_forestadmin_datasource-toolkit.ActionField.html).
{% endhint %}

### Properties

Fields are configurable using the following properties:

| Property       | Usage                              | Expected value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Description                                                                                                                                                                   |
| -------------- | ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type`         | **required**                       | `Boolean`, `Date`, `Dateonly`, `Enum`, `Json`, `Number`, `NumberList`, `EnumList`, `String`, `StringList`, `File`, `FileList` and [`Collection`](#references-to-records)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Set the [type of the field](https://forestadmin.github.io/agent-nodejs/interfaces/_forestadmin_datasource-toolkit.ActionFieldBase.html).                                      |
| `label`        | **required**                       | string                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Set the label of the field.                                                                                                                                                   |
| `id`           | *optional*                         | string                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Set the id of the field. The is used internally and to access values from the context. If not set the label will be used.                                                     |
| `description`  | *optional*                         | string                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Set the description of the field.                                                                                                                                             |
| `isRequired`   | *optional*                         | boolean                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Make the field required (default false).                                                                                                                                      |
| `defaultValue` | *optional*                         | any                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Set the default value of the field.                                                                                                                                           |
| `isReadOnly`   | *optional*                         | boolean                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Make the field read-only (default false).                                                                                                                                     |
| `enumValues`   | **required** when `type` is `Enum` | array of strings                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Change the list of possible values of the field when type is `Enum`.                                                                                                          |
| `widget`       | *optional*                         | `null`, [`AddressAutocomplete`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#address-autocomplete-widget), [`Checkbox`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#checkbox-widget), [`CheckboxGroup`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#checkbox-group-widget) , [`ColorPicker`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#color-picker-widget), [`CurrencyInput`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#currency-input-widget),[`DatePicker`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#datepicker-widget), [`Dropdown`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#dropdown-widget), [`FilePicker`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#file-picker-widget), [`JsonEditor`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#json-editor-widget), [`NumberInput`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#number-input-widget), [`NumberInputList`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#number-input-list-widget), [`RadioGroup`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#radio-group-widget), [`RichText`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#rich-text-widget), [`TextArea`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#text-area-widget), [`TextInput`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#text-input-widget), [`TextInputList`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#text-input-list-widget), [`TimePicker`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#time-picker-widget), [`UserDropdown`](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/forms-widgets#user-dropdown-widget) | Set the widget to use for the field. More info on the [dedicated page](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets). |

```javascript
agent.customizeCollection('customer', collection => {
  collection.addAction('Charge credit card', {
    scope: 'Single',
    form: [
      {
        label: 'amount',
        description: 'The amount (USD) to charge the credit card. Example: 42.50',
        type: 'Number',
        isRequired: true,
      },
    ],
    execute: async (context, resultBuilder) => {
      // Retrieve values entered in the form and columns from the selected record.
      const { amount } = context.formValues;
      const { stripeId, address } = await context.getRecord([
        'stripeId',
        'address:country',
      ]);

      /* ... Charge the credit card here ... */
      return resultBuilder.success('Amount charged!');
    },
  });
});
```

### References to records

![Reference widget on an action form](https://3861847666-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9UN5oBJhgzLadOqi7jx6%2Fuploads%2Fgit-blob-ca59b2cf9ca238abac1445bbfdda63345a2fb070%2Factions-form-collection.png?alt=media)

When using the `Collection` type, you can create a reference to a record of any collection.

The value of the field will be the primary key of the selected record.

{% hint style="info" %}
Note that the value will be stored in an array as the target collection may be using a composite primary key. When not using a composite primary key, the array can be assumed to contain a single value.
{% endhint %}

```javascript
agent.customizeCollection('ticket', collection => {
  collection.addAction('Assign ticket', {
    scope: 'Single',
    form: [
      {
        label: 'Assignee',
        description: 'The user to assign the ticket to',
        type: 'Collection',
        collectionName: 'user',
        isRequired: true,
      },
    ],
    execute: async (context, resultBuilder) => {
      // Retrieve user id from the form
      // (assuming the user collection has a single primary key)
      const [userId] = context.formValues.Assignee;
    },
  });
});
```
