From c2bd95eed74d4e15ae9bf69894a9ac6cfcce9f1e Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 3 Aug 2015 14:46:12 +0200 Subject: [PATCH] Move setting currentValues after we initialize the toggleables. It's needed because otherwise the DOM is slighltly different, for example the select has a default value, while after initializing the toggleables, if the select is not enabled, the default value is null. Fixes the annoying "unsaved changes" promp appearing even when no changes were made to the page. --- themes/grav/js/forms/form.js | 3 +++ themes/grav/js/pages-all.js | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) 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({