Define Actions and Events in Fragments

When developing fragments, you use actions to define what should happen in your user interface and events to trigger those actions, much the same as in pages or flows. However, the scope of these actions and events is confined to the fragment itself, ensuring that the fragment is independent but unaware of its parent container's context.

This means a fragment cannot call action chains defined in the container (say, a page, layout, or even another fragment) that uses this fragment. It also cannot listen to events fired by the parent container, but it can fire custom events that "emit" to the parent container. See Pass Data Between a Fragment and Its Parent Container.

How you define actions events in a fragment is similar to those in other scopes, but not all events from other scopes are available in fragments. Here’s a list of event types and events supported within a fragment:
Type of Event Description How to Define
Component events An event associated with a UI component in a page, including those in dynamic components. It’s possible to choose which event the component triggers, but available events will depend on the component. For example, an ojAction event is available to a button but not to an input text. Start an Action Chain From a Component
Variable events An event specific to a variable that occurs when the value stored in the variable changes. The only available variable event is onValueChanged. Start an Action Chain When a Variable Changes
Lifecycle events Predefined events that are automatically triggered during a fragment’s lifecycle:
  • vbEnter is triggered when the fragment state is activated.
  • vbExit is triggered when the fragment state is disposed (generally by navigating away from a page or the page is disposed).
Start an Action Chain From a Lifecycle Event
Custom events A user-defined event to start an action chain. Two types of custom events are supported in fragments:
  • An event that can be handled by listeners defined in the fragment. This event is similar to other custom events in VB Studio and is used to communicate consolidated state changes made in the fragment to the outer container.
  • An event that "emits" to the container. This event is used to propagate values to a fragment's parent container.