How to block weekend from selection on altField

How to block weekend from selection on altField

I have 2 fields: DeliveryDate and PickUpDate

DeliveryOffDate can be any date except Sundays or Public holidays: Sorted

PickUpDate is configured to default to DeliveryDate + 7 days

Problem: Delivery can be a Saturday BUT Pickup Cannot.

So, If a DeliveryDate is "Saturday", I want PickUpDate = DeliveryDate + 9 days (Monday)

  1. function nationalDays(date) {
  2. for (i = 0; i < natDays.length; i++) {
  3. if (date.getMonth() == natDays[i][0] - 1
  4. && date.getDate() == natDays[i][1]) {
  5. return [false, natDays[i][2] + '_day'];
  6. }
  7. }
  8. return [true, ''];
  9. }

  10. function noSundayOrHolidays(date) {
  11. var day = date.getDay();
  12. var next = new Date() + 1;
  13. var today = new Date();

  14. if ( day == 0 ) {
  15. return [''];
  16. } else {
  17. return nationalDays(date);
  18. }
  19. }
  20. function noWeekendOrHolidays(date) {
  21. var day = date.getDay();
  22. var next = new Date() + 1;
  23. var today = new Date();

  24. if (day == 0 || day == 7) {
  25. return [''];
  26. } else {
  27. return nationalDays(date);
  28. }
  29. }

  30. function setNextDay(date) {
  31. var day = date.getDay();
  32. if (day == 0) {
  33. return [''];
  34. } else {
  35. return nationalDays(date);
  36. }
  37. }

  38. jQuery('#deliveryDate').datepicker({
  39. beforeShowDay: noSundayOrHolidays,
  40. dateFormat: 'd/m/yy',
  41. changeMonth: true,
  42. changeYear: true,
  43. altField: "#pickUpDate",
  44. altFormat: "d/m/yy",
  45. minDate: +1,
  46. onSelect: function (_date, _datepicker) {
  47. var d = jQuery.datepicker.parseDate('d/m/yy', _date);
  48. d.setDate(d.getDate() + 7); // Add seven days
  49. jQuery('#pickUpDate').datepicker('setDate', d);

  50. // if its after 17h alert that request will be processed the next day
  51. var now = new Date();
  52. if (parseInt(now.getHours()) >= 17) {
  53. //alert('Our working hours have passed. You can proceed with the booking but details will be processed in the morning.');
  54. var message = "Our working hours have passed. You can proceed with the booking but details will be processed in the morning.";
  55. $( "<div />" ).dialog({
  56. modal: true,
  57. title: "After 5PM Notification",
  58. width: 500,
  59. open: function() {
  60. $(this).html(message);
  61. },
  62. buttons: {
  63. Confirm: function() {
  64. $(this).dialog("close");
  65. }
  66. }
  67. });
  68. }
  69. reCalculatePrice();
  70. },
  71. onClose: function() {
  72. jQuery('#pickUpDate').focus();
  73. }
  74. });

  75. jQuery('#pickUpDate').datepicker({
  76. beforeShowDay: noWeekendOrHolidays,
  77. dateFormat: 'd/m/yy',
  78. minDate: +5,
  79. changeMonth: true,
  80. changeYear: true,
  81. onSelect: function (_date, _datepicker) {
  82. var pickupDate = jQuery.datepicker.parseDate('d/m/yy', _date);
  83. var delDate = jQuery('#deliveryDate').val();
  84. var delDate_arr = delDate.split('/');
  85. var deliveryDate = new Date(delDate_arr[2], delDate_arr[1]-1, delDate_arr[0]);
  86. //Check and make sure the Pickup Date is after the Delivery Date
  87. if ( deliveryDate.getTime() > pickupDate.getTime() ) {
  88. jQuery('#pickUpDate').val('');
  89. alert('Pickup Date must be later than Delivery Date');
  90. }
  91. reCalculatePrice();
  92. }

  93. });
    • Topic Participants

    • info