Components
← All components

Unsaved-Changes Guard

stimeo--dirty-form

Detects form edits and warns before leaving with unsaved changes (unload + Turbo visit).

  • Rails / Turbo

The stimeo--dirty-form controller snapshots the form's field values on connect, marks the form data-dirty once a value changes (and clears it when values return to the baseline), and — while dirty — guards both a full unload (beforeunload) and a Turbo visit (turbo:before-visit). On a Turbo visit it dispatches a cancelable stimeo--dirty-form:guard event; if a consumer cancels it (or confirmBridge is set) the visit is blocked, otherwise it falls back to a native confirm(message). A successful submit — the markClean action or turbo:submit-end — clears the dirty state. It also dispatches stimeo--dirty-form:dirty when the state flips. Behavior only — it renders no confirmation UI (pair with a Confirm Bridge) and does not persist input (pair with Persist). beforeunload is wired only while dirty, and every listener is removed on disconnect (Turbo navigation included).

running
Unsaved changes