This will monitor the user input for unsaved changes and show a confirmation box if the user attempts to leave the page. The script adds the "oc-data-changed" class to the form element when the form data is changed.

<form
    data-change-monitor
    data-window-close-confirm="There is unsaved data"
>
    ...
</form>

Example

Click the "Mark changed" button and "Reload page".

<form
    data-window-close-confirm="There is unsaved data"
    data-change-monitor>

    <button type="button" onclick="$(this).trigger('change')">
        Mark changed
    </button>

    <button type="button" onclick="$(this).trigger('unchange.oc.changeMonitor')">
        Mark saved
    </button>

    <hr />

    <button type="button" onclick="window.location.reload()">
        Reload page
    </button>

</form>

Supported data attributes

Supported events

Triggered events

JavaScript API

$('#form').changeMonitor()