From 942d0c01555f22b2ca6708fa9d4e4b29db3aed2e Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Mon, 24 Oct 2016 14:37:17 -0400 Subject: [PATCH] adding new product fields for the token shipping, hiding and setting height to 0 using js for the token form gravity forms --- functions.php | 5 +++-- js/app.js | 26 +++++++++++++++++++++++++- js/custom/pageSetup.js | 26 +++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/functions.php b/functions.php index 7068d72..7750109 100644 --- a/functions.php +++ b/functions.php @@ -320,15 +320,16 @@ if (!function_exists('is_in_tree')) { add_action( 'gform_after_submission', 'set_post_content', 10, 2 ); function set_post_content( $entry, $form ) { - + echo '
', print_r($entry), '
'; if($form['id'] === 4){ - + if ( $entry['36.3'] > 1){ $qty = $entry['36.3'] - 1; $qty = ($qty * 2) + 3; $entry['38.2'] = '$' . $qty; $entry['38.2'] = 2; } + } if ( $form['gfpdf_form_settings'] ){ diff --git a/js/app.js b/js/app.js index b31fe43..373cadd 100644 --- a/js/app.js +++ b/js/app.js @@ -65,8 +65,27 @@ $(document).ready(function () { $("#ginput_quantity_4_38").val( first_shipping ); $("#ginput_quantity_4_39").val( additional_shipping ); + }); - + + $(document).on("change, keyup", ".ginput_quantity", function(){ + var qty_total = 0; + for(var i = 12; i < 36; i++){ + if(i !== 36 || i !== 37){ + if( $('#ginput_quantity_4_' + i).val() !== undefined && $('#ginput_quantity_4_' + i).val() !== '' ){ + console.log($('#ginput_quantity_4_' + i).val()); + qty_total += parseInt($('#ginput_quantity_4_' + i).val(), 10); + } + } + } + if( qty_total < 5 ){ + + } + console.log(qty_total); + + }); + + console.log("test"); $(document).on("change, keyup", "#ginput_quantity_4_37", function(){ $("#ginput_quantity_4_42").val( $(this).val() ); }); @@ -74,6 +93,11 @@ $(document).ready(function () { $("#field_4_38").css({"visibility": "hidden", "height" : 0}); $("#field_4_39").css({"visibility": "hidden", "height" : 0}); $("#field_4_42").css({"visibility": "hidden", "height" : 0}); + + $("#field_4_48").css({"visibility": "hidden", "height" : 0}); + $("#field_4_49").css({"visibility": "hidden", "height" : 0}); + $("#field_4_50").css({"visibility": "hidden", "height" : 0}); + $("#input_4_41").attr("readonly", true); $("#input_4_47").attr("readonly", true); }); diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 8c210a5..977cc64 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -56,8 +56,27 @@ $(document).ready(function () { $("#ginput_quantity_4_38").val( first_shipping ); $("#ginput_quantity_4_39").val( additional_shipping ); + }); - + + $(document).on("change, keyup", ".ginput_quantity", function(){ + var qty_total = 0; + for(var i = 12; i < 36; i++){ + if(i !== 36 || i !== 37){ + if( $('#ginput_quantity_4_' + i).val() !== undefined && $('#ginput_quantity_4_' + i).val() !== '' ){ + console.log($('#ginput_quantity_4_' + i).val()); + qty_total += parseInt($('#ginput_quantity_4_' + i).val(), 10); + } + } + } + if( qty_total < 5 ){ + + } + console.log(qty_total); + + }); + + console.log("test"); $(document).on("change, keyup", "#ginput_quantity_4_37", function(){ $("#ginput_quantity_4_42").val( $(this).val() ); }); @@ -65,6 +84,11 @@ $(document).ready(function () { $("#field_4_38").css({"visibility": "hidden", "height" : 0}); $("#field_4_39").css({"visibility": "hidden", "height" : 0}); $("#field_4_42").css({"visibility": "hidden", "height" : 0}); + + $("#field_4_48").css({"visibility": "hidden", "height" : 0}); + $("#field_4_49").css({"visibility": "hidden", "height" : 0}); + $("#field_4_50").css({"visibility": "hidden", "height" : 0}); + $("#input_4_41").attr("readonly", true); $("#input_4_47").attr("readonly", true); }); -- 2.17.1