Back to October

Change Monitor

modules/system/assets/toolbox/controls/change-monitor/README.md

4.3.01.4 KB
Original Source

Change Monitor

Monitors form inputs for unsaved changes and warns the user before leaving the page. Adds the oc-data-changed class to the form element when changes are detected.

Basic Usage

html
<form data-change-monitor>
    <input type="text" name="title" />

    <button type="button" data-change-monitor-commit>
        Save
    </button>
</form>

JavaScript API

js
$('#form').changeMonitor()

Static Methods

  • ChangeMonitorControl.disable() — Globally disable all change monitors
  • ChangeMonitorControl.enable() — Re-enable all change monitors

Data Attributes

AttributeDescription
data-change-monitorEnables the plugin on a form
data-change-monitor-commitMarks changes as saved when clicked

Events (listened)

EventDescription
changeMarks form data as changed
unchange.oc.changeMonitorMarks form data as unchanged
pause.oc.changeMonitorTemporarily pauses monitoring
resume.oc.changeMonitorResumes monitoring
pauseUnloadListener.oc.changeMonitorPauses the beforeunload warning
resumeUnloadListener.oc.changeMonitorResumes the beforeunload warning

Events (triggered)

EventDescription
changed.oc.changeMonitorFired when form data changes
unchanged.oc.changeMonitorFired when form data is uncommitted
ready.oc.changeMonitorFired when initialization completes