# Form

## Overview

The Form component is used to quickly update or add new records to your database.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FsWqqFCTpjoq1BSOYdIZm%2FCleanShot%202025-07-30%20at%2012.02.33%402x-min.png?alt=media&#x26;token=3bf45fe8-24d3-41d0-a264-f5c497ec8229" alt=""><figcaption></figcaption></figure>

### Properties

<table><thead><tr><th width="124.046875">Name</th><th width="117.59765625">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>Component name</td></tr><tr><td><code>value</code></td><td><code>value</code></td><td>Key-value object</td></tr><tr><td><code>valid</code></td><td><code>boolean</code></td><td>Indicates if the component is valid</td></tr><tr><td><code>validating</code></td><td><code>boolean</code></td><td>Indicates if the component is validating</td></tr></tbody></table>

### Methods

<table><thead><tr><th width="230.51953125">Name</th><th width="231.5">Parameters</th><th width="99.8515625">Returns</th><th>Description</th></tr></thead><tbody><tr><td><code>setValue</code></td><td><code>data: object</code></td><td><code>void</code></td><td>Set component data</td></tr><tr><td><code>setSubmitButtonDisabled</code></td><td><code>disabled: boolean</code></td><td><code>void</code></td><td>Disable or enable the submit button</td></tr><tr><td><code>reset</code></td><td>–</td><td><code>void</code></td><td>Reset component to the initial value</td></tr><tr><td><code>validate</code></td><td>–</td><td><code>void</code></td><td>Trigger form validation</td></tr><tr><td><code>resetValidation</code></td><td>–</td><td><code>void</code></td><td>Clear validation errors</td></tr><tr><td><code>setErrors</code></td><td><p><code>errors: { [key: string]:</code></p><p> <code>string } | null</code></p></td><td><code>void</code></td><td>Mark the form as invalid and display errors</td></tr><tr><td><code>submit</code></td><td>–</td><td><code>void</code></td><td>Trigger submit event</td></tr></tbody></table>

### Triggers

<table><thead><tr><th width="230.984375">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>On Init</strong></td><td>Triggered when the component is initialized</td></tr><tr><td><strong>On Submit</strong></td><td>Triggered when the component data is submitted</td></tr><tr><td><strong>On Change</strong></td><td>Triggered when the component's state changes</td></tr><tr><td><strong>On Click</strong></td><td>Triggered when the component is clicked</td></tr><tr><td><strong>On Double Click</strong></td><td>Triggered when the component is double-clicked</td></tr><tr><td><strong>On Custom Button Click</strong></td><td>Triggered when the custom button is clicked</td></tr><tr><td><strong>On Custom Button Double Click</strong></td><td>Triggered when the custom button is double-clicked</td></tr></tbody></table>

## Working with the component

### Best practices

Check out these articles to learn how you can utilize the Form component in different scenarios:point\_down:

{% content-ref url="../../concepts/components/work-with-components/linking-components" %}
[linking-components](https://docs.uibakery.io/concepts/components/work-with-components/linking-components)
{% endcontent-ref %}

{% content-ref url="../../build-from-scratch/getting-started/send-a-form" %}
[send-a-form](https://docs.uibakery.io/build-from-scratch/getting-started/send-a-form)
{% endcontent-ref %}

{% content-ref url="../../concepts/components/work-with-components/create-a-single-form-to-add-and-update-data" %}
[create-a-single-form-to-add-and-update-data](https://docs.uibakery.io/concepts/components/work-with-components/create-a-single-form-to-add-and-update-data)
{% endcontent-ref %}

### Form & field settings

#### View/Edit settings

In the *Edit settings* section, for any editable field you can specify the **Input mask** you need (for example, Uppercase/lowercase) and the **Field tooltip**. These settings will be applied to data display if the *Do not allow editing this field* checkbox is <mark style="color:red;">NOT</mark> selected.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FSg6BFQ2KUUXT6dtYZkMa%2FCleanShot%202025-01-15%20at%2017.54.20%402x-min.png?alt=media&#x26;token=9c06f9f8-c778-4ec9-bbbd-7ad4b879b43e" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
*View settings* only work for fields with the **Do not allow editing this field** checkbox selected.
{% endhint %}

#### Fields validation

You can validate Form fields by clicking on the necessary field and navigating to the *Edit settings* section. There, you can set up the *Regexp pattern* and the error message, as well as set the min/max length for the field.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FJRzJZvlYZ3Q6o6nbtAKe%2FCleanShot%202025-07-30%20at%2015.34.49%402x-min.png?alt=media&#x26;token=c22df892-58e1-463c-9835-299466a811dc" alt=""><figcaption></figcaption></figure>

#### Setting default values for Form fields

It's possible to configure default values for any Form field. You can set them up in the component's **Data** property using the following format: `{field: 'default_value'}`, for example, `{text: 'Hi!'}`.&#x20;

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FeZImYyOGJ7FB3iB5nATw%2FCleanShot%202025-07-30%20at%2015.53.41%402x-min.png?alt=media&#x26;token=401d6ef2-7ebe-4253-802b-7e5a82e20d0f" alt=""><figcaption></figcaption></figure>

#### Changing an input value while editing

In some cases, it may be necessary to predefine the input value or change it depending on another field's value. To do so, you can use the **Value** property in the field's *Edit settings* section. It works similarly to the Input component's default *Value* field.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FphVlp9Y4TUgYDPZmqMwr%2FCleanShot%202025-07-30%20at%2016.10.45%402x-min.png?alt=media&#x26;token=e9e2c476-96b1-4476-b265-e25d807cbd44" alt=""><figcaption></figcaption></figure>

Let's review a couple of examples of using the Value field:

* <mark style="background-color:blue;">Automatically populate the Initials field</mark>

Imagine you have a Form with some default data and the following fields: *Id*, *First name* and L*ast name*. Now, you also want to automatically display the initials of the user.

1. Add a new *Initials* field to the Form - select the *String* type.
2. Now, expand this field's *Edit settings* section and add the following code to the *Value* property:

`{{parent.value.first_name?.[0] || ''}}{{parent.value.last_name?.[0] || ''}}`;

That's it! Now, when you fill in the First and Last name fields, the value of the Initials field will be automatically updated depending on your input.

{% @arcade/embed flowId="vnJTbNMsBMCi02269S3s" url="<https://app.arcade.software/share/vnJTbNMsBMCi02269S3s>" %}

* <mark style="background-color:blue;">Change Select options depending on another field's value</mark>

Let's say you have a Form with the *Season* and *Month* fields and you want to display only the months corresponding to the specified season. Here's how you can configure this:

1. Create an action of the *JavaScript Code* type (`getAvailableOptions` here) and add the following code:

```js
return {
  Winter: ['December', 'January', 'February'],
  Spring: ['March', 'April', 'May'],
  Summer: ['June', 'July', 'August'],
  Autumn: ['September', 'October', 'November'],
};
```

2. Now, select the Form's **Month** field, change its type to *Select/Tag*, and add the following code to the **Options** property in the *General settings* section (in the JS mode):

```js
{{actions.getAvailableOptions.data?.[parent.value.season] ?? []}}
```

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2Ft8wAlS8JBMjtKw6WvckX%2FCleanShot%202025-07-30%20at%2016.52.49%402x.png?alt=media&#x26;token=7a54e42d-a702-4a16-964d-201bca8b13a4" alt=""><figcaption></figcaption></figure>

Done! Now specify the season in the Form and check the available options for the month.

{% @arcade/embed flowId="DeZBncNwUJQCCwvhKO3K" url="<https://app.arcade.software/share/DeZBncNwUJQCCwvhKO3K>" %}

### Dynamic structure configuration

It's possible to use the JS mode for dynamic configuration of the Form's structure. To enable the mode, you just need to click the button next to component *Structure* in the right side panel.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FVxH6xBrXQNCG6bYYqZAT%2FCleanShot%202025-07-31%20at%2012.28.52%402x-min.png?alt=media&#x26;token=bffeedfc-cc75-4a98-be23-40e12a57c005" alt=""><figcaption></figcaption></figure>

You can specify Form structure using an array of objects and strings. If an object is used, it can define the following properties:

* *prop* - data property to display
* *type* - one of the available types: 'number', 'string', 'text', 'image', 'link', 'button', 'contextMenuButton', 'boolean', 'currency', 'date', 'datetime', 'file', 'jsoneditor', 'time', 'select', 'multiselect'.
* primaryKey, color, text, and others.

{% hint style="info" %}
Refer to [this article](https://docs.uibakery.io/reference/working-with-components/dynamic-structure-properties) for a full list of all supported properties.
{% endhint %}

This is an example of a dynamic structure configuration:

<pre class="language-javascript"><code class="lang-javascript"><strong>[
</strong>  'full_name',
  { prop: 'id', type: 'number', color: 'danger' }, 
  { prop: 'full_name' },
  { prop: 'avatar', type: 'image' },
  { prop: 'email', type: 'link' },
  { 
    prop: 'email',
    type: 'button',
    text: '\{\{value\}\}',
    triggers: {
        buttonClick: [ "console.log('Button click', \{\{value\}\})" ],
    },
  },
];
</code></pre>

{% hint style="success" %}
If the type is not specified, *string* is used by default. The required key is *prop*.
{% endhint %}
