Skip to content
Skip to main contentWhere does your team stand on AI adoption?
CONTACT SALESSTART BUILDING

Custom actions

Define custom actions to trigger on Element events by registering actions within your codebase. Use custom actions to trigger functions within your codebase, such as engagement events or tracking details.

This feature is accessible within the Classic UI mode of the Visual Editor.

What to know

  • Use the registerAction() function to register custom actions.
  • Once a content entry has access to a custom action, access it within the Element Events panel in the Data tab.

Register a custom action

Within your codebase, register a custom action with the registerAction() function. Your custom action will require an id, name, kind, and action.

Framework
Meta-Framework
SDK Generation
import { Builder } from "@builder.io/react"; Builder.registerAction({ id: "alert-action", name: "Alert Action", kind: "function", action: () => `alert("An alert has been triggered.");`, });

Each key-value pair functions in the following way:

  • id: a globally unique ID for an action
  • name: the name that will appear within the Visual Editor for the action
  • kind: the type of action; can be function, expression, or any
  • action: a function that returns a string representation of code that should run when the action is triggered

Add custom inputs

For more dynamic custom actions, add inputs to your actions. The inputs key can be added to the argument for registerAction(), which accepts an array of input objects.

These values can then be accessed within the action anonymous function. In the example below, a new input with a name of alertMessage is created that is required and accepts a string. The value of this input is then used within the action anonymous function.

Framework
Meta-Framework
SDK Generation
import { Builder } from "@builder.io/react"; Builder.registerAction({ name: "Alert Action", kind: "function", id: "alert-action", inputs: [ { name: "alertMessage", type: "string", required: true, helperText: "Type your alert message here", }, ], action: (options) => `alert("${options.alertMessage}");`, });

Use your custom action

To use the custom action you've registered within your content entry:

These values can then be accessed within the action anonymous function. In the example below, a new input with a name of alertMessage is created that is required and accepts string. The value of this input is then used within the action anonymous function.

In the video below, a button is selected and a custom Alert Action is triggered on button click. This causes an alert to appear on the page with the string provided to the custom input.

What's next

Was this article helpful?