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)
- function nationalDays(date) {
- for (i = 0; i < natDays.length; i++) {
- if (date.getMonth() == natDays[i][0] - 1
- && date.getDate() == natDays[i][1]) {
- return [false, natDays[i][2] + '_day'];
- }
- }
- return [true, ''];
- }
- function noSundayOrHolidays(date) {
- var day = date.getDay();
- var next = new Date() + 1;
- var today = new Date();
- if ( day == 0 ) {
- return [''];
- } else {
- return nationalDays(date);
- }
- }
-
- function noWeekendOrHolidays(date) {
- var day = date.getDay();
- var next = new Date() + 1;
- var today = new Date();
- if (day == 0 || day == 7) {
- return [''];
- } else {
- return nationalDays(date);
- }
- }
- function setNextDay(date) {
- var day = date.getDay();
- if (day == 0) {
- return [''];
- } else {
- return nationalDays(date);
- }
- }
- jQuery('#deliveryDate').datepicker({
- beforeShowDay: noSundayOrHolidays,
- dateFormat: 'd/m/yy',
- changeMonth: true,
- changeYear: true,
- altField: "#pickUpDate",
- altFormat: "d/m/yy",
- minDate: +1,
- onSelect: function (_date, _datepicker) {
- var d = jQuery.datepicker.parseDate('d/m/yy', _date);
- d.setDate(d.getDate() + 7); // Add seven days
- jQuery('#pickUpDate').datepicker('setDate', d);
- // if its after 17h alert that request will be processed the next day
- var now = new Date();
- if (parseInt(now.getHours()) >= 17) {
- //alert('Our working hours have passed. You can proceed with the booking but details will be processed in the morning.');
- var message = "Our working hours have passed. You can proceed with the booking but details will be processed in the morning.";
- $( "<div />" ).dialog({
- modal: true,
- title: "After 5PM Notification",
- width: 500,
- open: function() {
- $(this).html(message);
- },
- buttons: {
- Confirm: function() {
- $(this).dialog("close");
- }
- }
- });
- }
- reCalculatePrice();
- },
- onClose: function() {
- jQuery('#pickUpDate').focus();
- }
- });
- jQuery('#pickUpDate').datepicker({
- beforeShowDay: noWeekendOrHolidays,
- dateFormat: 'd/m/yy',
- minDate: +5,
- changeMonth: true,
- changeYear: true,
- onSelect: function (_date, _datepicker) {
- var pickupDate = jQuery.datepicker.parseDate('d/m/yy', _date);
- var delDate = jQuery('#deliveryDate').val();
- var delDate_arr = delDate.split('/');
- var deliveryDate = new Date(delDate_arr[2], delDate_arr[1]-1, delDate_arr[0]);
-
- //Check and make sure the Pickup Date is after the Delivery Date
- if ( deliveryDate.getTime() > pickupDate.getTime() ) {
-
- jQuery('#pickUpDate').val('');
- alert('Pickup Date must be later than Delivery Date');
- }
- reCalculatePrice();
- }
- });