mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-03-16 22:10:28 +00:00
User interaction with the form within the 10s delay also won’t trigger the confirmation message. There will still be race condition issues if form widgets like rich text take 10+ seconds to initialise – but that doesn’t seem likely.
This commit is contained in:
parent
56aadf8407
commit
6deb5a8656
1 changed files with 9 additions and 2 deletions
|
|
@ -57,16 +57,23 @@ function enableDirtyFormCheck(formSelector, options) {
|
|||
var $form = $(formSelector);
|
||||
var confirmationMessage = options.confirmationMessage || ' ';
|
||||
var alwaysDirty = options.alwaysDirty || false;
|
||||
var initialData = $form.serialize();
|
||||
var initialData = null;
|
||||
var formSubmitted = false;
|
||||
|
||||
$form.on('submit', function() {
|
||||
formSubmitted = true;
|
||||
});
|
||||
|
||||
// Delay snapshotting the form’s data to avoid race conditions with form widgets that might process the values.
|
||||
// User interaction with the form within that delay also won’t trigger the confirmation message.
|
||||
setTimeout(function() {
|
||||
initialData = $form.serialize();
|
||||
}, 1000 * 10);
|
||||
|
||||
window.addEventListener('beforeunload', function(event) {
|
||||
var isDirty = initialData && $form.serialize() != initialData;
|
||||
var displayConfirmation = (
|
||||
!formSubmitted && (alwaysDirty || $form.serialize() != initialData)
|
||||
!formSubmitted && (alwaysDirty || isDirty)
|
||||
);
|
||||
|
||||
if (displayConfirmation) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue