Fires an event that is defined in the Widget API.
The fireEvent()
function fires a widget event, which can then be handled from outside the widget (by code in a parent widget or a site page).
When using the widget's API, the event is named on
, for example, onAddedToCart
.
function fireEvent(eventName: string, data: object): void;
The name of te event to be fired.
A data object that is passed to the event handler.
$w(`#button1`).onClick(() => {
$widget.fireEvent(`addedToCart`, {
productId: product.id,
customerId: customer.id,
});
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.