From 76884766ec19d6e00326ecdf42df922c8734ffd8 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 9 Sep 2024 17:19:39 +0530 Subject: [PATCH 1/3] Improve the 'Existing Product Meta' button --- templates/admin/ppom-fields.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/templates/admin/ppom-fields.php b/templates/admin/ppom-fields.php index 192d0a40..8ac92375 100644 --- a/templates/admin/ppom-fields.php +++ b/templates/admin/ppom-fields.php @@ -51,7 +51,7 @@ ) ); -echo '

' . __( '« Existing Product Meta', 'woocommerce-product-addon' ) . '

'; +echo '

' . __( '« Existing Product Meta', 'woocommerce-product-addon' ) . '

'; $product_id = isset( $_GET['product_id'] ) ? intval( $_GET['product_id'] ) : ''; @@ -412,10 +412,6 @@ class="dashicons dashicons-edit"> -

-

-
render_field_settings(); ?>
From 7bd2dc16bac748ead3f944477428e039f10d9426 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 9 Sep 2024 18:13:04 +0530 Subject: [PATCH 2/3] Add javascript unsaved warning --- js/admin/ppom-admin.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/js/admin/ppom-admin.js b/js/admin/ppom-admin.js index 23f5c1d9..43c11516 100644 --- a/js/admin/ppom-admin.js +++ b/js/admin/ppom-admin.js @@ -1356,6 +1356,29 @@ jQuery(function($) { $(clone_new_field).find('input[data-metatype="jquery_dp"]').change(toggleHandler.activateHandler); } ); + // Unsaved form exit confirmation. + var unsaved = false; + $( ':input' ).change(function () { + if ( $( this ).parents( '.ppom-checkboxe-style' )?.length > 0 ) { + unsaved = false; + return; + } + unsaved = true; + }); + $( '.ppom-submit-btn input.btn, button.ppom_copy_field' ).on( 'click', function() { + if ( $(this).hasClass('ppom_copy_field') ) { + unsaved = true; + return; + } + unsaved = false; + } ); + window.addEventListener( 'beforeunload', function( e ) { + if ( unsaved ) { + e.preventDefault(); + e.returnValue = ''; + } + }); + $(document).ready(function(){ $('.ppom-slider').each(function(i, item){ const itemEl = $(item); From c0d50aed58c86a482a725a492f010d79ba92299e Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 9 Sep 2024 18:28:37 +0530 Subject: [PATCH 3/3] Fix issue with new field --- js/admin/ppom-admin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/admin/ppom-admin.js b/js/admin/ppom-admin.js index 43c11516..93bab193 100644 --- a/js/admin/ppom-admin.js +++ b/js/admin/ppom-admin.js @@ -1365,8 +1365,8 @@ jQuery(function($) { } unsaved = true; }); - $( '.ppom-submit-btn input.btn, button.ppom_copy_field' ).on( 'click', function() { - if ( $(this).hasClass('ppom_copy_field') ) { + $( document ).on( 'click', '.ppom-submit-btn input.btn, button.ppom_copy_field, button.ppom-add-fields-js-action', function() { + if ( $(this).hasClass('ppom_copy_field') || $(this).hasClass( 'ppom-add-fields-js-action' ) ) { unsaved = true; return; }