From: Anthony Talarico Date: Fri, 31 May 2019 16:46:46 +0000 (-0400) Subject: fixing the golf quote form javascript to get correct dates and count X-Git-Tag: v1.0.5^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=e410d02df63d9816d0cad8b142fe944f361b9d98;p=WP-Themes%2Fmeetmtp.git fixing the golf quote form javascript to get correct dates and count --- diff --git a/footer.php b/footer.php index 186c5c1..d71aca7 100644 --- a/footer.php +++ b/footer.php @@ -118,8 +118,6 @@ if ( ! defined( 'ABSPATH' ) ) { var option = $(el).clone(); $(".cell2B").append( option ); $(".cell2A").append( $(el) ); - // $(".cell2B").append( $(el) ); - // document.getElementById('cell2B').appendChild(el); } }); @@ -132,72 +130,72 @@ if ( ! defined( 'ABSPATH' ) ) { golfDate = $('#input_8_3').datepicker('getDate'); $("[name='input_60']").datepicker('setDate', golfDate); date1 = $('#input_8_6').val(); - date1.toString(); - date1 = date1.replace(/\//g, ""); - date1 = parseInt(date1, 10); } }); $("#input_8_33").datepicker({ dateFormat: 'mm/dd/yy', - onSelect: function (dateText) { date2 = $('#input_8_33').val(); - date2.toString(); - date2 = date2.replace(/\//g, ""); - date2 = parseInt(date2, 10); - numDays = ((date2 - date1) / 10000 + 1); + var date1Obj = new Date(date1); + var date2Obj = new Date(date2); + var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds + var firstDate = new Date(date2); // 29th of Feb at noon your timezone + var secondDate = new Date(date1); // 2st of March at noon + numDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime()) / (oneDay))) + 1; // cloning loop $('#field_8_60').find('#input_8_60').attr("name", 'input_60[]'); - - if( $("#gform_8 .gfield_list_group").length > 2){ - // for (j = 1; j < $("#gform_8 .gfield_list_group").length ; j++) { + if(firstDate > secondDate){ + - // $("#removeRowBtn").trigger("click"); - // $("#removeRowBtn2").trigger("click"); - - // } + if( $("#gform_8 .gfield_list_group").length > 2){ + $(".gfield_list_group").each(function(index){ + if(index > 0){ + $("#rowA"+ index).remove(); + $("#rowB"+ index).remove(); + } + }) + } + for (j = 0; j < numDays - 1; j++) { + + $("#rowBtn").trigger("click"); + $("#rowBtn2").trigger("click"); + } - $(".gfield_list_group").each(function(index){ - if(index > 0){ - $("#rowA"+ index).remove(); - $("#rowB"+ index).remove(); - } - - }) - } - for (j = 0; j < numDays - 1; j++) { - - $("#rowBtn").trigger("click"); - $("#rowBtn2").trigger("click"); - } - - $('.add_list_item').removeClass("add_list_item"); - $('.delete_list_item').removeClass("delete_list_item"); - for (j = 0; j < $("#field_8_56 .gfield_list tbody tr").length; j++) { - $("#table1 > tbody > tr").eq(j).attr("id", "rowA" + j); - $("#table2 > tbody > tr").eq(j).attr("id", "rowB" + j); - - $("#rowA" + j).find("[name='input_56[]']").attr("id", "cell" + j); - $("#rowB" + j).find("[name='input_57[]']").attr("id", "cell" + j); - $("#cell" + j).attr("readonly", true); - $("#table2 #cell" + j).attr("readonly", true); - } - - $('.gfield_list_56_cell2').find("[name='input_56[]']").addClass('cell2A'); - $('.gfield_list_57_cell2').find("[name='input_57[]']").addClass('cell2B'); - $('.gfield_list_56_cell3').find("[name='input_56[]']").attr("id", 'cell3A'); - $('.gfield_list_57_cell3').find("[name='input_57[]']").attr("id", 'cell3B'); - $('.gfield_list_56_cell4').find("[name='input_56[]']").attr("id", 'cell4A'); - $('.gfield_list_57_cell4').find("[name='input_57[]']").attr("id", 'cell4B'); - j = golfDate; - staticGolfDate = $('#input_8_3').datepicker('getDate'); - - $('#cell0').val((staticGolfDate.getMonth() + 1) + "/" + staticGolfDate.getDate() + "/" + staticGolfDate.getFullYear()); - $('#table2 #cell0').val((j.getMonth() + 1) + "/" + j.getDate() + "/" + j.getFullYear()); - - for (i = 1; i < $("#field_8_57 .gfield_list tbody tr").length; i++) { - $('#cell' + i).val((staticGolfDate.getMonth() + 1) + "/" + (staticGolfDate.getDate() + i) + "/" + staticGolfDate.getFullYear()); - $('#table2 #cell' + i).val((staticGolfDate.getMonth() + 1) + "/" + (staticGolfDate.getDate() + i) + "/" + staticGolfDate.getFullYear()); + $('.add_list_item').removeClass("add_list_item"); + $('.delete_list_item').removeClass("delete_list_item"); + for (j = 0; j < $("#field_8_56 .gfield_list tbody tr").length; j++) { + $("#table1 > tbody > tr").eq(j).attr("id", "rowA" + j); + $("#table2 > tbody > tr").eq(j).attr("id", "rowB" + j); + + $("#rowA" + j).find("[name='input_56[]']").attr("id", "cell" + j); + $("#rowB" + j).find("[name='input_57[]']").attr("id", "cell" + j); + $("#cell" + j).attr("readonly", true); + $("#table2 #cell" + j).attr("readonly", true); + } + + $('.gfield_list_56_cell2').find("[name='input_56[]']").addClass('cell2A'); + $('.gfield_list_57_cell2').find("[name='input_57[]']").addClass('cell2B'); + $('.gfield_list_56_cell3').find("[name='input_56[]']").attr("id", 'cell3A'); + $('.gfield_list_57_cell3').find("[name='input_57[]']").attr("id", 'cell3B'); + $('.gfield_list_56_cell4').find("[name='input_56[]']").attr("id", 'cell4A'); + $('.gfield_list_57_cell4').find("[name='input_57[]']").attr("id", 'cell4B'); + j = golfDate; + staticGolfDate = new Date($('#input_8_3').datepicker('getDate')); + + $('#cell0').val((staticGolfDate.getMonth() + 1) + "/" + staticGolfDate.getDate() + "/" + staticGolfDate.getFullYear()); + $('#table2 #cell0').val((j.getMonth() + 1) + "/" + j.getDate() + "/" + j.getFullYear()); + var start = 0; + var date = new Date(date1); + for (i = 1; i < $("#field_8_57 .gfield_list tbody tr").length + 1; i++) { + var cellDate = staticGolfDate.setDate(staticGolfDate.getDate() + 1); + var cellValue = ((staticGolfDate.getMonth() + 1) + "/" + (staticGolfDate.getDate()) + "/" + staticGolfDate.getFullYear()); + $('#cell' + i).val(cellValue); + $('#table2 #cell' + i).val(cellValue); + start++; + } + }else{ + alert("Departure date must be after arrival date") + $('#input_8_33').val(''); } } });