From: Anthony Talarico Date: Wed, 3 Jan 2018 12:46:53 +0000 (-0500) Subject: fixing the donation form javascript validation X-Git-Tag: v1.0.7^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=cd1a069bbed7433b0dd3e996afb2ba0c10ab6963;p=WP-Themes%2Fphsacf.git fixing the donation form javascript validation adding more javascript validation to the donation page code for the amount input --- diff --git a/js/app.js b/js/app.js index 2ddcb3e..cfa7539 100644 --- a/js/app.js +++ b/js/app.js @@ -22,7 +22,10 @@ var g=a(f(this.selector(c),a("
").html(c.attr("title")).html())),h=thi var add_remove = page.find('.gfield_list_icons').children('img'); var total_input = page.find(".ginput_container_total"); var total = 0; - + var form = $('#gform_3'); + var missing_value = false; + var amount = 0; + // set up autocomplete $('.gfield_list_2_cell2').children().autocomplete({source: tags}); @@ -45,28 +48,66 @@ var g=a(f(this.selector(c),a("
").html(c.attr("title")).html())),h=thi $(donate_fields).on('blur', '.gfield_list_2_cell1 > input', function(){ var _ = $(this); + var fund_field = _.parent().next().children('input'); var amount_input = page.find(".gfield_list_2_cell1").children(); var rows = amount_input.length; + var stripped = strip_nan( _.val() ); + stripped = parseFloat(stripped); + + //set amount to 0 if NaN + if( isNaN( stripped ) ){ + $(_).val(''); + }else{ + $(_).val(stripped); + } + total = 0; $.each(amount_input, function(index, value){ - + var fund = $(this).parent().next().children('input').val(); var amount = $(this).val(); + amount = strip_nan(amount); amount = parseFloat(amount); - if(amount && !isNaN(amount)){ + + if( isNaN(amount)){ + amount = 0; + } + + if(amount >= 0 && !isNaN(amount)){ total += amount; total_input.children('#input_3_1').val(total.toFixed(2)); total_input.children( '.ginput_total' ).text('$' + total.toFixed(2)); - } else if(rows <= 1) { - total_input.children('#input_3_1').val(0); - total_input.children( '.ginput_total' ).text('$0.00'); - total = 0; - } + } + }); + $('.gfield_hidden_product').last() .find( $("[id^='ginput_base']") ).val('$' + total.toFixed(2)); }); + + $("#gform_submit_button_3").on("click", function(e){ + if(total <= 0){ + alert("Please enter an amount greater than 0"); + return false; + } else{ + $(form).on("submit").submit(); + } + }) + + + + // $(document).on('submit',form, function(e){ + // console.log("asdf"); + // if(missing_value){ + // alert("Please enter an amount greater than 0"); + // e.preventDefault(); + // // $(this).unbind('submit'); + // } else { + // return + // } + // }) + }); });;// Load foundation $(document).foundation(); diff --git a/js/custom/donate.js b/js/custom/donate.js index e1fddfb..a57794e 100644 --- a/js/custom/donate.js +++ b/js/custom/donate.js @@ -13,7 +13,10 @@ $(function(){ var add_remove = page.find('.gfield_list_icons').children('img'); var total_input = page.find(".ginput_container_total"); var total = 0; - + var form = $('#gform_3'); + var missing_value = false; + var amount = 0; + // set up autocomplete $('.gfield_list_2_cell2').children().autocomplete({source: tags}); @@ -36,27 +39,65 @@ $(function(){ $(donate_fields).on('blur', '.gfield_list_2_cell1 > input', function(){ var _ = $(this); + var fund_field = _.parent().next().children('input'); var amount_input = page.find(".gfield_list_2_cell1").children(); var rows = amount_input.length; + var stripped = strip_nan( _.val() ); + stripped = parseFloat(stripped); + + //set amount to 0 if NaN + if( isNaN( stripped ) ){ + $(_).val(''); + }else{ + $(_).val(stripped); + } + total = 0; $.each(amount_input, function(index, value){ - + var fund = $(this).parent().next().children('input').val(); var amount = $(this).val(); + amount = strip_nan(amount); amount = parseFloat(amount); - if(amount && !isNaN(amount)){ + + if( isNaN(amount)){ + amount = 0; + } + + if(amount >= 0 && !isNaN(amount)){ total += amount; total_input.children('#input_3_1').val(total.toFixed(2)); total_input.children( '.ginput_total' ).text('$' + total.toFixed(2)); - } else if(rows <= 1) { - total_input.children('#input_3_1').val(0); - total_input.children( '.ginput_total' ).text('$0.00'); - total = 0; - } + } + }); + $('.gfield_hidden_product').last() .find( $("[id^='ginput_base']") ).val('$' + total.toFixed(2)); }); + + $("#gform_submit_button_3").on("click", function(e){ + if(total <= 0){ + alert("Please enter an amount greater than 0"); + return false; + } else{ + $(form).on("submit").submit(); + } + }) + + + + // $(document).on('submit',form, function(e){ + // console.log("asdf"); + // if(missing_value){ + // alert("Please enter an amount greater than 0"); + // e.preventDefault(); + // // $(this).unbind('submit'); + // } else { + // return + // } + // }) + }); }); \ No newline at end of file diff --git a/package.json b/package.json index 0a67921..2d7df3d 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,9 @@ "grunt-contrib-uglify": "~0.7.0", "grunt-contrib-concat": "~0.5.0", "grunt-contrib-copy": "~0.7.0" + }, + "dependencies": { + "request": "~2.81.0", + "node-sass": "~4.7.2" } -} \ No newline at end of file +} diff --git a/parts/header-meta.php b/parts/header-meta.php index 00f2d5a..3871eda 100644 --- a/parts/header-meta.php +++ b/parts/header-meta.php @@ -2,7 +2,7 @@ <?php wp_title(); ?> - + diff --git a/style.css b/style.css index 3c9366c..e606b0c 100644 --- a/style.css +++ b/style.css @@ -3,5 +3,5 @@ Theme Name: Petoskey-HarborSpringsCommunityFoundation Author: Gaslight Media Author URI: http://www.gaslightmedia.com Description: A theme for Petoskey-HarborSpringsCommunityFoundation -Version: 1.0.6 +Version: 1.0.7 */