diff --git a/themes/grav/js/forms/form.js b/themes/grav/js/forms/form.js index d87965d6..a0973728 100644 --- a/themes/grav/js/forms/form.js +++ b/themes/grav/js/forms/form.js @@ -113,6 +113,9 @@ scanToggleable(this); scan(this); this.scanned = true; + + //We can now initialize window.currentValues as toggleables are initialized + window.currentValues = getState(); }; Form.factories = {}; diff --git a/themes/grav/js/pages-all.js b/themes/grav/js/pages-all.js index 36ec1346..c4357bfd 100644 --- a/themes/grav/js/pages-all.js +++ b/themes/grav/js/pages-all.js @@ -12,8 +12,10 @@ var getState = function(){ $(function(){ - var currentValues = getState(), - clickedLink; + //defined to make clear it's global, but initialized in ./forms/form.js: we must wait to scan the + //toggleables elements, otherwise the DOM changes and `beforeunload` detects unsaved changes + var currentValues; + var clickedLink; // selectize $('input.page-filter').selectize({