From d7478546ea87958b09b3f018ddb309cc3f68084b Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 3 Dec 2015 08:16:08 -0500 Subject: [PATCH] fixing off canvas datepicker logic --- js/app.js | 10 ++++++---- js/custom/pageSetup.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) 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(""); } }); -- 2.17.1