Learn how to create self-contained, reusable custom components that integrate third-party JavaScript libraries like FullCalendar, Leaflet maps, Chart.js, and more.
Overview
BetterForms custom components can integrate any JavaScript library using lifecycle hooks. This guide shows you how to:
[onBeforeMount] β Component waits here
β
Component Renders to DOM
β
[onMount] β DOM elements are now available
β
Component is Interactive
β (when data changes)
[onUpdated]
β (when removing)
[onBeforeDestroy]
β
Component Removed
β
[onDestroyed]
// β WRONG - this.$refs is NOT available in namedAction functions
const element = this.$refs.myElement;
// β WRONG - schema is NOT directly accessible
const config = schema.calendarConfig;
// β WRONG - component instance properties
const value = this.myProperty;
// β Standard DOM queries
const element = document.getElementById('myElement');
const element = document.querySelector('#myElement');
// β Model data
const events = model.calendarEvents;
const config = model.chartConfig;
// β App state
const user = app.currentUser;
// β Global storage
window._myLibraryInstance = instance;
// β BetterForms utilities
await BF.libraryLoadOnce('...');
<!-- β Good -->
<div id="chartContainer"></div>
<div id="mapRoot"></div>
<div id="editorElement"></div>
<!-- β Avoid - ref won't work in namedActions -->
<div ref="myElement"></div>