From: Anthony Talarico Date: Thu, 3 Dec 2015 13:16:08 +0000 (-0500) Subject: fixing off canvas datepicker logic X-Git-Tag: v1.0.0^2~160 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d7478546ea87958b09b3f018ddb309cc3f68084b;p=WP-Themes%2Fstaffords.git fixing off canvas datepicker logic --- diff --git a/js/app.js b/js/app.js index 0133814..56c973d 100644 --- a/js/app.js +++ b/js/app.js @@ -46,6 +46,7 @@ $(document).ready(function () { $("#kidsOff").val(""); $(document).on('change', '#arriveOff', function () { + currentDate = $("#arriveOff").val(); currentDate = new Date(currentDate); currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); @@ -66,12 +67,13 @@ $(document).ready(function () { start = "arrival_date=" + y + '-' + m + '-' + d + '&'; minDays = y + '-' + m + '-' + dd; $("#departOff").attr("min", minDays); - $("#nightsOff").val(Math.ceil(currentDate2 - currentDate) / (1000 * 60 * 60 * 24)); - if ($("#nightsOff").val() <= 0) { - $("#departOff").val("Minimum 1 Night"); + if ($("#departOff").val() === "Departure Date" || $("#departOff").val() === "") { $("#nightsOff").val(""); + } else { + $("#nightsOff").val(Math.ceil(currentDate2 - currentDate) / (1000 * 60 * 60 * 24)); } - if ($("#departOff").val() === "Departure Date") { + if ($("#nightsOff").val() <= 0) { + $("#departOff").val("Minimum 1 Night"); $("#nightsOff").val(""); } }); diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index ae20a7f..b20d1e6 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -37,6 +37,7 @@ $(document).ready(function () { $("#kidsOff").val(""); $(document).on('change', '#arriveOff', function () { + currentDate = $("#arriveOff").val(); currentDate = new Date(currentDate); currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); @@ -57,12 +58,13 @@ $(document).ready(function () { start = "arrival_date=" + y + '-' + m + '-' + d + '&'; minDays = y + '-' + m + '-' + dd; $("#departOff").attr("min", minDays); - $("#nightsOff").val(Math.ceil(currentDate2 - currentDate) / (1000 * 60 * 60 * 24)); - if ($("#nightsOff").val() <= 0) { - $("#departOff").val("Minimum 1 Night"); + if ($("#departOff").val() === "Departure Date" || $("#departOff").val() === "") { $("#nightsOff").val(""); + } else { + $("#nightsOff").val(Math.ceil(currentDate2 - currentDate) / (1000 * 60 * 60 * 24)); } - if ($("#departOff").val() === "Departure Date") { + if ($("#nightsOff").val() <= 0) { + $("#departOff").val("Minimum 1 Night"); $("#nightsOff").val(""); } });