Added flag to enable/dissable check for leaving a page the pending changes.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 9 Aug 2019 20:54:39 +0000 (16:54 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 9 Aug 2019 20:54:39 +0000 (16:54 -0400)
views/adminServerStats.html
views/adminServerStatsConfig.html
views/ui/f6/form-start.html

index 5f95c51..ed99767 100755 (executable)
                     'action'    => "{$thisUrl}?page={$thisPage}&selected_site={$selectedSite}",
                     'method'    => 'POST',
                     'validate'  => true,
-                    'validateFocusMsg' => true
+                    'validateFocusMsg' => true,
+                    'leaveModifiedFormCheck' => true
                 ]}
                 {include file="ui/f6/form-start.html"}
 
index 68a707c..c22e1aa 100755 (executable)
@@ -16,7 +16,8 @@
                 'validate'          => true,
                 'validateID'        => '1234',
                 'validateFocusMsg'  => true,
-                'validateMessage'   => 'There are some errors in your form. Please check the highlighted fields below.'
+                'validateMessage'   => 'There are some errors in your form. Please check the highlighted fields below.',
+                'leaveModifiedFormCheck' => true
             ]}
             {include file="ui/f6/form-start.html"}
 
index 7550f8b..e94cb20 100644 (file)
@@ -8,14 +8,15 @@
     validate message.
 
     {$ui = [
-        'action'            => string   Required    URL
-        'method'            => string   Required    Method "post" or "get"
-        'id'                => string               Form id
-        'file'              => boolean              If including file upload set to true
-        'validate'          => boolean              If true, include Abide Form Validation
-        'validateFocusMsg'  => boolean              If true focuses on validateMessage on error - May be a problem if there's more than one validated form (may have to ID these messages separately)
-        'validateID'        => string               Unique text that will be added to the validate message container to ensure that it is unique
-        'validateMessage'   => string               Message to show for a validation error, Defaults to "There are some errors in your form."
+        'action'                 => string   Required    URL
+        'method'                 => string   Required    Method "post" or "get"
+        'id'                     => string               Form id
+        'file'                   => boolean              If including file upload set to true
+        'validate'               => boolean              If true, include Abide Form Validation
+        'validateFocusMsg'       => boolean              If true focuses on validateMessage on error - May be a problem if there's more than one validated form (may have to ID these messages separately)
+        'validateID'             => string               Unique text that will be added to the validate message container to ensure that it is unique
+        'validateMessage'        => string               Message to show for a validation error, Defaults to "There are some errors in your form."
+        'leaveModifiedFormCheck' => boolean              If set and user tries to leave the page after modifying form input it will warn them and ask if they want to abandon their changes.
     ]}
 *}
 <form
 
         jQuery(document).ready(function($){
 
-            // When submit button is clicked, disable the beforeunload message
-            $('.glm-form-submit-button').on('click', function() {
-                glmFormDataChangesPending = false;
-                return true;
-            });
-
-            // If submit is required and we're laving the page, alert the user
-            $(window).on('beforeunload', function(){
-
-                // Check if any of the wp_editor instances is dirty (tinyMCE)
-                // ** THIS MAY NOT BE A GOOD LONG TERM SOLUTION **
-                if (typeof tinyMCE != "undefined" && typeof tinyMCE.editors != "undefined") {
-                    for(i=0; i<tinyMCE.editors.length; i++){
-                        if (!tinymce.editors[i].isNotDirty) {
-                            glmFormDataChangesPending = true;
-                        }
-                     }
-                }
-
-                if (glmFormDataChangesPending) {
+            {if !empty($ui.leaveModifiedFormCheck)}
+
+                // When submit button is clicked, disable the beforeunload message
+                $('.glm-form-submit-button').on('click', function() {
+                    glmFormDataChangesPending = false;
                     return true;
-                }
+                });
+
+                // If submit is required and we're laving the page, alert the user
+                $(window).on('beforeunload', function(){
+
+                    // Check if any of the wp_editor instances is dirty (tinyMCE)
+                    // ** THIS MAY NOT BE A GOOD LONG TERM SOLUTION **
+                    if (typeof tinyMCE != "undefined" && typeof tinyMCE.editors != "undefined") {
+                        for(i=0; i<tinyMCE.editors.length; i++){
+                            if (!tinymce.editors[i].isNotDirty) {
+                                glmFormDataChangesPending = true;
+                            }
+                         }
+                    }
 
-                return;
-            });
+                    if (glmFormDataChangesPending) {
+                        return true;
+                    }
+
+                    return;
+                });
+
+            {/if}
 
             // Setup field validation
             {if !empty($ui.validateFocusMsg)}