From c7355b80b04551a34c3094c0e425461ea353109d Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 10 Nov 2015 09:12:58 -0500 Subject: [PATCH] adjusting restrictions for off canvas date input --- js/app.js | 60 ++++++++++++++++++++++++++++++++++++++++-- js/custom/pageSetup.js | 60 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/js/app.js b/js/app.js index 7f03c2b..b78478c 100644 --- a/js/app.js +++ b/js/app.js @@ -27,15 +27,71 @@ $(document).ready(function () { $("#res-tab").attr("id", "res-tab-open"); } else { $("#res-tab-open").attr("id", "res-tab"); - } + } }); - var start, end, arrival, departure, stay, d, m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&', + var start, end, arrival, currentDate, requiredDate, minDays, departure, stay, d, m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&', crookedRiver = 'ZhWXD46i2%2fq319vcR%2fcw69rZvA2bz%2fttOOxO9t1%2fBJ0%3d&', adults, kids, perry = 'RtXm7mjas4tWRxEAkt8ienQMPRR5EbsZGSOalE8V63s%3d&'; ///////off canvas date picker logic ////////////////////////////////////////////// + // restrict arrival date //////////////////////////////// + $(document).on('change', '#arriveOff', function () { + currentDate = $("#arriveOff").val(); + currentDate = new Date(currentDate); + currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); + currentDate.setDate(currentDate.getDate()); + d = currentDate.getDate(); + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + requiredDate = y + '-' + m + '-' + d; + + if (requiredDate < $('#arriveOff').attr("min")) { + minDays = $('#arriveOff').attr("min"); + $("#arriveOff").val(minDays); + $("#departOff").val($('#departOff').attr("min")); + } else { + d = currentDate.getDate() + 2; + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + requiredDate = y + '-' + m + '-' + d; + $("#dateOff2").val(requiredDate); + } + + }); + // restrict departure date /////////////////////////////// + $(document).on('change', '#departOff', function () { + currentDate = $("#departOff").val(); + currentDate = new Date(currentDate); + currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); + currentDate.setDate(currentDate.getDate()); + d = currentDate.getDate() + 2; + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + requiredDate = y + '-' + m + '-' + d; + if ($("#departOff").val() < $('#departOff').attr("min")) { + // $("#dateOff2").val(requiredDate); + } + }); /* $("#arriveOff").datepicker({ onSelect: function (date) { $("#arriveOff").datepicker({dateFormat: 'mm/dd/yy'}).val(); diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 1079ab1..c699443 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -18,15 +18,71 @@ $(document).ready(function () { $("#res-tab").attr("id", "res-tab-open"); } else { $("#res-tab-open").attr("id", "res-tab"); - } + } }); - var start, end, arrival, departure, stay, d, m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&', + var start, end, arrival, currentDate, requiredDate, minDays, departure, stay, d, m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&', crookedRiver = 'ZhWXD46i2%2fq319vcR%2fcw69rZvA2bz%2fttOOxO9t1%2fBJ0%3d&', adults, kids, perry = 'RtXm7mjas4tWRxEAkt8ienQMPRR5EbsZGSOalE8V63s%3d&'; ///////off canvas date picker logic ////////////////////////////////////////////// + // restrict arrival date //////////////////////////////// + $(document).on('change', '#arriveOff', function () { + currentDate = $("#arriveOff").val(); + currentDate = new Date(currentDate); + currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); + currentDate.setDate(currentDate.getDate()); + d = currentDate.getDate(); + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + requiredDate = y + '-' + m + '-' + d; + + if (requiredDate < $('#arriveOff').attr("min")) { + minDays = $('#arriveOff').attr("min"); + $("#arriveOff").val(minDays); + $("#departOff").val($('#departOff').attr("min")); + } else { + d = currentDate.getDate() + 2; + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + requiredDate = y + '-' + m + '-' + d; + $("#dateOff2").val(requiredDate); + } + + }); + // restrict departure date /////////////////////////////// + $(document).on('change', '#departOff', function () { + currentDate = $("#departOff").val(); + currentDate = new Date(currentDate); + currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); + currentDate.setDate(currentDate.getDate()); + d = currentDate.getDate() + 2; + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + requiredDate = y + '-' + m + '-' + d; + if ($("#departOff").val() < $('#departOff').attr("min")) { + // $("#dateOff2").val(requiredDate); + } + }); /* $("#arriveOff").datepicker({ onSelect: function (date) { $("#arriveOff").datepicker({dateFormat: 'mm/dd/yy'}).val(); -- 2.17.1