Trigger an event, either native or custom, and optionally pass data along.

Parameters:
NameTypeDescription
optsObject

The options object.

Properties
NameTypeDescription
dataobject

Data to pass inside an object with the event. Available as event.detail in the listener.

elDocument | Window | HTMLElement

The element to trigger the event on.

eventstring

The event name.

nativeboolean

Whether or not the event is a native browser event or a custom one.

Since
  • 1.0.0
Returns:
Type: 
void
Example
import { trigger } from "@gravityforms/utils";

function Example() {
    trigger( { event: 'gform/flyout/open', native: false, data: {
        something: 'we need',
    } } );
};

// elsewhere in the codebase

document.addEventListener( 'gform/flyout/open', function( event ) {
    console.log( event.detail.something );
} );

Requires

  • module:assign