# Event handlers

In Appizap, event handlers are responsible for collecting and processing events from components and queries, and executing subsequent actions. For example, for a **Button** component, you can add an event handler to trigger the **Run query** action in response to the button **Click** event.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FRRRmZuDOUEW9jl5B743E%2Fimage.png?alt=media&#x26;token=f9b5793d-cd98-4ad0-9995-5e1301f16698" alt=""><figcaption></figcaption></figure>

Set event handlers wisely to provide a reactive and responsive user experience (UX). For example, triggering a **get-all** query after **insert-new-data** query finishes enables table automatically to refresh.

{% hint style="info" %}
You can add as many event handlers as you want for a single component or query, and these event handlers run concurrently.
{% endhint %}

## Events

### Component events

Different components have different events. For example, **Button** components only have a **Click** event.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FAadEzOjOVjfyj1w9uUbY%2Fimage.png?alt=media&#x26;token=ee36f284-e7c0-4b9c-8bdd-e165c3b30dba" alt=""><figcaption></figcaption></figure>

**Input** components have **Change**, **Focus**, **Blur**, and **Submit** events.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FbBWX9zedYcgJ6cyp2TC9%2Fimage.png?alt=media&#x26;token=05e308c6-d6ec-459a-8d49-91ea9fe54696" alt=""><figcaption></figcaption></figure>

### Query events

Running a query can result in success or failure, so queries have two events: **Success** or **Failure**. You can add event handlers to queries in Query editor.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FbnnFoNuCT1O5iTNBIG0V%2Fimage.png?alt=media&#x26;token=3fd069f6-a94a-432d-b351-f9bf10e19cf0" alt=""><figcaption></figcaption></figure>

## Actions

There are a number of event handler actions available in Appizap for handling different scenarios. Set them in the **Action** dropdown list in an event handler.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FrH48ZPDkvW1eie5Z6u7T%2Fimage.png?alt=media&#x26;token=a72c98ae-d590-4b67-be09-37f0ad6d8e0e" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
See [advanced](#advanced) on this page to know advanced settings.
{% endhint %}

### Run a Workflow

Select and trigger a workflow that was defined earlier using Workflow Builder.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FGhP1dpSXiNfOtIAyThLU%2Fimage.png?alt=media&#x26;token=601d217a-9e5b-4980-94ba-d6b0dd0bae08" alt=""><figcaption></figcaption></figure>

### Run query

Trigger the selected query.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Faoi5CWSTlHfuJaZ3XtEM%2Fimage.png?alt=media&#x26;token=5e0ba277-4270-4601-ad2b-1fa9e56463da" alt=""><figcaption></figcaption></figure>

### Control components

To control a component, select a component in the **Component** dropdown list and call one of its methods in the **Method** dropdown list.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fd3zi7og9wqS7NBvDxsTl%2Fimage.png?alt=media&#x26;token=2b6fc084-9cad-445b-a9f5-b398f3c3aba1" alt=""><figcaption></figcaption></figure>

### Set temporary state

Store data in a [temporary state](https://docs.appizap.ae/build-apps/write-javascript/temporary-state).

### Go to app

Navigate to an Appizap app with optional query or hash parameters.

| Parameter            | Function                                                                                        |
| -------------------- | ----------------------------------------------------------------------------------------------- |
| <p>URL Query<br></p> | <p>Append <code>?key1=value1\&key2=value2...</code> to the URL of the app to be opened.<br></p> |
| URL Hash             | Append `#key1=value1&key2=value2...` to the URL of the app to be opened.                        |

### Go to URL

Navigate to an external URL.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FPiLBkmTh4T64ROY9CDDL%2Fimage.png?alt=media&#x26;token=a5c0c0d1-ae9e-4eaa-864a-2ea9d7169ce7" alt=""><figcaption></figcaption></figure>

### Show notification

Show a floating notification of informational, success, warning, or error message.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FbmhVA58A1o4iFDQkHrYE%2Fimage.png?alt=media&#x26;token=2cf9f49d-c208-493a-ad44-dd299546f700" alt=""><figcaption></figcaption></figure>

### Copy to clipboard

Copy a value to the clipboard.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FGpxWJnMsmzA2GC5fUzAS%2Fimage.png?alt=media&#x26;token=30786ebe-6a2d-406d-9a35-bf446fbd358b" alt=""><figcaption></figcaption></figure>

### Export data

Export data in a certain file type.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FG9UUTQxyMut7XRrijiZS%2Fimage.png?alt=media&#x26;token=bff93c05-152d-48d3-b1b2-3c7ca54f07ee" alt=""><figcaption></figcaption></figure>

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FOAbGOPpomtN6OHuyDcmP%2Fimage.png?alt=media&#x26;token=4c194d2f-43f2-4bd7-a07a-65e85429ebec" alt=""><figcaption><p>Export file types</p></figcaption></figure>

## Advanced

### Only run when

The action can be triggered only under a specified condition. Configure the running condition of an event handler in **Only run when** option, and then the event handler runs only when this condition evaluates to `true`.

### Debounce and throttle

**Debounce** and **Throttle** reduce the frequency of triggering the action.

#### **Debounce**

Debounce delays an action. Once a debounce time is set, the action will not be executed immediately following the event until the debounce time passes. If the event occurs again before the time ends, the debounce time will be retimed. For example, an input component triggers a query once the user changes the text. If the query is expensive to run and you don't want to run it after every single character is typed, you can delay the execution of the query by setting the debounce time. Then the query will only run after the user finishes typing.

#### **Throttle**

Throttle lets an action happen only once during a specified period of time. By default, every single event triggers an action, but sometimes running an action can be costly. For example, you set an event handle to trigger **Run query** action to update data in response to the **Click** event, but you find that query too expensive to run, then you can set a throttle time to let the query run only once within a given time.
