fixing off canvas datepicker logic
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 3 Dec 2015 13:16:08 +0000 (08:16 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 3 Dec 2015 13:16:08 +0000 (08:16 -0500)
js/app.js
js/custom/pageSetup.js

index 0133814..56c973d 100644 (file)
--- 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("");
         }
     });
index ae20a7f..b20d1e6 100644 (file)
@@ -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("");
         }
     });