adding more javascript validation to the donation page code for the amount input
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});
$(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();
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});
$(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
"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
+}
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><?php wp_title(); ?></title>
- <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri() ; ?>/css/app.css?v=1.0.6">
+ <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri() ; ?>/css/app.css?v=1.0.7">
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri() ; ?>/favicon.ico">
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,400italic,700' rel='stylesheet' type='text/css'>
<?php wp_head(); ?>
Author: Gaslight Media
Author URI: http://www.gaslightmedia.com
Description: A theme for Petoskey-HarborSpringsCommunityFoundation
-Version: 1.0.6
+Version: 1.0.7
*/