Chapter 26
Events and loading
Every form emits one set of typed events (PixiFormEventMap). You can listen in three equivalent ways:
// 1. In the config: registered before mounting starts, so early events like `load` are never missed
await mountPixiForm(host, { fields, onSubmit, on: { load: (e) => console.log(`ready in ${e.ms} ms`) } });
// 2. On the handle (typed payloads; returns an unsubscribe function)
const off = handle.on('change', (e) => console.log(e.name));
handle.once('success', (e) => router.navigate('/welcome'));
// 3. As DOM events on <pixi-form> (detail = the same payload)
el.addEventListener('pixiform-change', (e) => console.log(e.detail.name));
26.1 Loading the UI#
| Event | Payload | When |
|---|---|---|
beforeload |
{ config } |
<pixi-form> only, before anything is built. Cancelable (preventDefault()), and detail.config can be edited. |
loadstart |
{ reason } |
Mounting starts ('eager', 'visible' or 'idle'). |
load |
{ ms, fields, width, height } |
The first frame is painted and the form is interactive. Also await handle.loaded. |
resize |
{ width, height } |
The canvas changed size. |
themechange |
{ theme, mode } |
setTheme() or the OS light/dark setting changed. |
a11ychange |
{ prefs } |
High contrast, reduced motion, forced colors or text scale changed. |
error |
{ error, phase } |
Mounting failed ('load'), the submit handler threw ('submit'), or one of your listeners threw ('listener'). |
destroy |
{} |
handle.destroy() ran: secrets are wiped and the canvas removed. |
<pixi-form> also fires pixiform-ready with { handle }.
Choose when to build the form with load:
mountPixiForm(host, { load: 'visible', loadMargin: '300px', fields, onSubmit }); // when near the viewport
mountPixiForm(host, { load: 'idle', fields, onSubmit }); // when the browser is idle
Show a placeholder while loading. The host carries data-pixiform-state (waiting → loading → ready, or
error, then destroyed), and aria-busy="true" while it isn't ready:
pixi-form[data-pixiform-state='waiting'],
pixi-form[data-pixiform-state='loading'] { min-height: 480px; background: var(--skeleton); }
pixi-form[data-pixiform-state='error']::after { content: 'The form could not be loaded.'; }
26.2 Form activity#
| Event | Payload | When |
|---|---|---|
focus / blur |
{ name } |
A field gains or loses focus (composites like PhoneInput count as one field). |
change |
{ name, value } |
A value changed. Password fields give a Secret handle, never text. |
dirty |
{ name } |
First real user edit since load or reset (programmatic setValues doesn't count). Use it for "unsaved changes" prompts; handle.isDirty() reads it. |
validate |
{ name, error, code } |
A field's validation result changed. |
grouptoggle |
{ group, expanded } |
A FieldGroup opened or folded. |
beforesubmit |
{ values, preventDefault() } |
Validation passed, just before submitting. Cancelable, and not counted against the rate limit. |
submitting |
{} |
The bot check and rate limit passed; your handler is running. |
success / failure |
{ result } |
The handler's { ok, message, fieldErrors }. |
invalid |
{ errors } |
Client-side validation failed. |
blocked |
{ reason, code } |
Rate limit ('rate_limit') or bot check ('bot'). |
reset |
{} |
handle.reset() ran (also clears dirty). |
idle |
{} |
Secrets were wiped after inactivity. |
For a confirmation step, cancel the first attempt and submit again once the person agrees:
let confirmed = false;
handle.on('beforesubmit', (e) => {
if (confirmed) return;
e.preventDefault();
showDialog('Create the account?').then((yes) => { if (yes) { confirmed = true; handle.submit(); } });
});
Error isolation: a listener that throws doesn't stop other listeners or the matching DOM event. It's reported as
an error event with phase: 'listener'. The Angular wrapper exposes (loaded) and a catch-all
(formEvent) output ({ type, detail }).