docs/docs/en/interface-builder/event-flow.md
Event flow allows you to trigger custom actions when certain events occur, such as form changes. Beyond forms, pages, blocks, buttons, and fields can all use event flows to configure custom operations.
Let's walk through a simple example to understand how to configure event flows. We'll create a linkage between two tables where clicking a row in the left table automatically filters the data in the right table.
Configuration steps:
A universal event that can be used in pages, blocks, buttons, or fields. Use this event for initialization tasks, such as configuring different data scopes based on different conditions.
A table block-specific event. Triggers when a table row is clicked. When triggered, it adds a "Clicked row record" to the context, which can be used as a variable in conditions and steps.
A form block-specific event. Triggers when form field values change. You can access form values through the "Current form" variable in conditions and steps.
A button-specific event. Triggers when the button is clicked.
In event flow settings, two concepts are easy to mix up:
Many pages, blocks, and actions have built-in behavior (for example: submit, open a dialog, request data). When you add a custom event flow on the same event (such as “Click”), “Execution timing” decides:
Tip: if you’re not sure which built-in flow/step to pick, the first two options are usually enough.
Create a custom variable to use within the context.
Custom variables have scope. For example, a variable defined in a block's event flow can only be used within that block. To make a variable available across all blocks on the current page, configure it in the page's event flow.
Use values from a form block as a variable. Configuration:
More variable types will be supported in the future.
Set the data scope for a target block. Configuration:
Refresh target blocks. Multiple blocks can be configured. Configuration:
Navigate to a URL. Configuration:
Display global feedback messages.
Display global notification alerts.
Display notification alerts in the four corners of the system. Commonly used for:
Execute JavaScript code.
When you need to call an external API or third-party service within a flow, you can use Custom request to trigger a custom HTTP request. Common scenarios include:
After the request completes, its response data can continue to be used in subsequent steps for data processing, conditional checks, storage, and more.
GET, POST, PUT, or DELETE.Authorization and Content-Type.GET requests.POST, PUT, and similar requests. You can provide JSON, form data, and more.ctx.steps.Scenario: trigger an event flow in a form, call a third-party API, and fill a form field with the response.
Example setup:
const res = await ctx.api.request({
method: 'get',
url: 'https://jsonplaceholder.typicode.com/users/2',
skipNotify: true,
// Note: ctx.api will include the current NocoBase authentication/custom headers by default
// Here we override it with an "empty Authorization" to avoid sending the token to a third party
headers: {
Authorization: 'Bearer ',
},
});
const username = res?.data?.username;
// replace it with actual field name
ctx.form.setFieldsValue({ username });