From f5aaf5f46076e0ac11ab52ef2ea940fd789ff174 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 19 May 2022 21:30:40 +0200 Subject: New limit option when reloading a feed (#4370) --- p/scripts/extra.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'p/scripts/extra.js') diff --git a/p/scripts/extra.js b/p/scripts/extra.js index e20fe821c..a95eb620d 100644 --- a/p/scripts/extra.js +++ b/p/scripts/extra.js @@ -233,11 +233,18 @@ function init_select_observers() { }); } -function data_leave_validation(parent) { +/** + * Returns true when no input element is changed, false otherwise. + * When excludeForm is defined, will only report changes outside the specified form. + */ +function data_leave_validation(parent, excludeForm = null) { const ds = parent.querySelectorAll('[data-leave-validation]'); for (let i = ds.length - 1; i >= 0; i--) { const input = ds[i]; + if (excludeForm && excludeForm === input.form) { + continue; + } if (input.type === 'checkbox' || input.type === 'radio') { if (input.checked != input.getAttribute('data-leave-validation')) { return false; @@ -251,7 +258,7 @@ function data_leave_validation(parent) { function init_configuration_alert() { window.onsubmit = function (e) { - window.hasSubmit = true; + window.hasSubmit = data_leave_validation(document.body, e.submitter ? e.submitter.form : null); }; window.onbeforeunload = function (e) { if (window.hasSubmit) { -- cgit v1.2.3