Fix: only add "confirm-leave" when form has it specified

This commit is contained in:
bergware
2022-11-12 12:17:31 +01:00
parent 31eedd7dbe
commit 4a48e0c012
@@ -945,8 +945,10 @@ $(function() {
form.find('input[value="<?=_("Done")?>"],input[value="Done"]').not('input.lock').val("<?=_('Reset')?>").prop('onclick',null).off('click').click(function(){formHasUnsavedChanges=false;refresh(form.offset().top);});
});});
// add leave confirmation when form has changed without applying (opt-in function)
$('form.js-confirm-leave').on('change',function(e){formHasUnsavedChanges=true;}).on('submit',function(e){formHasUnsavedChanges=false;});
$(window).on('beforeunload',function(e){if (formHasUnsavedChanges) return '';}); // note: the browser creates its own popup window and warning message
if ($('form.js-confirm-leave').length>0) {
$('form.js-confirm-leave').on('change',function(e){formHasUnsavedChanges=true;}).on('submit',function(e){formHasUnsavedChanges=false;});
$(window).on('beforeunload',function(e){if (formHasUnsavedChanges) return '';}); // note: the browser creates its own popup window and warning message
}
// form parser: add escapeQuotes protection
$('form').each(function(){
var action = $(this).prop('action').actionName();