Re is out: see what's new Lifetime updates on every purchase Support replies within 24 hours Secure checkout via Gumroad 8,500+ sales since 2016

↑↓ Navigate ↵ Open Esc Close

All products
Re:Maily contact form builder is now available on WordPress.org See it live

JavaScript events

Updated 2 min read 14 views

The grid sends events when it starts and when its items change. They bubble, so one listener on document hears every grid on the page.

// Refresh a custom cursor after new items come in
document.addEventListener( 'forma:updated', ( event ) => {
	myTheme.cursor.refresh( event.detail.items );
} );

// Don't load the next page while a popup is open
document.addEventListener( 'forma:before-load', ( event ) => {
	if ( document.body.classList.contains( 'popup-open' ) ) {
		event.preventDefault();
	}
} );

Grid events

EventWhen
forma:initThe grid is ready
forma:before-loadA request starts; preventDefault() cancels it
forma:updatedNew items are in; detail.items lists them
forma:filteredAfter updated, when the filter changed
forma:searchedAfter updated, when the search changed
forma:sortedAfter updated, when the order changed
forma:paginatedAfter updated, for page numbers and Load More
forma:errorThe request failed

Each detail has grid (the element), layout, layoutSettings, page, maxPages, term, search, sort, and for loads also action, append and items.

EventSent onWhen
forma:lightbox-slideThe element a slide comes fromBefore the slide shows. detail.item is its data, which a listener can change
forma:lightbox-opendocumentBefore the lightbox opens. detail.pswp is the PhotoSwipe instance, detail.trigger the element clicked

Methods

window.formaGrid has two methods for your scripts:

// Start the grids in markup added after the page loaded, such as a popup
formaGrid.init( popupElement );

// Show page 3 of a grid, given the grid or one of its controls
formaGrid.page( gridElement, 3 );
Was this article helpful?