# 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](/files/XwqyDw4CDoSpkcqlG6Xt)

## 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`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#address-autocomplete-widget), [`Checkbox`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#checkbox-widget), [`CheckboxGroup`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#checkbox-group-widget) , [`ColorPicker`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#color-picker-widget), [`CurrencyInput`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#currency-input-widget),[`DatePicker`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#datepicker-widget), [`Dropdown`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#dropdown-widget), [`FilePicker`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#file-picker-widget), [`JsonEditor`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#json-editor-widget), [`NumberInput`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#number-input-widget), [`NumberInputList`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#number-input-list-widget), [`RadioGroup`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#radio-group-widget), [`RichText`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#rich-text-widget), [`TextArea`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#text-area-widget), [`TextInput`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#text-input-widget), [`TextInputList`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#text-input-list-widget), [`TimePicker`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#time-picker-widget), [`UserDropdown`](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md#user-dropdown-widget) | Set the widget to use for the field. More info on the [dedicated page](/developer-guide-agents-nodejs/agent-customization/actions/forms-widgets.md). |

```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](/files/HndtXNcGa8OK02ch9pex)

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;
    },
  });
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/forms-static.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
