I'm using Jquery's Datepicker and have a set of 5 buttons next to the calendar to select the coming 1-5 days. I already have the weekends grayed out but when I click the buttons, they still select weekends days. How do I make it ignore weekends and only count business days? (e.g. if I click 2 days on a Friday it should select Tuesday)
Here is my code
$(function(){
$('.rfq_ship_date').datepicker({
beforeShowDay: $.datepicker.noWeekends
});
});
$(".1day").click(function(){$(".rfq_ship_date").datepicker("setDate", "+1")});
$(".2day").click(function(){$(".rfq_ship_date").datepicker("setDate", "+2")});
$(".3day").click(function(){$(".rfq_ship_date").datepicker("setDate", "+3")});
$(".4day").click(function(){$(".rfq_ship_date").datepicker("setDate", "+4")});
$(".5day").click(function(){$(".rfq_ship_date").datepicker("setDate", "+5")});
EDIT: Here is the related HTML
<div class="field">
<%= f.label :ship_date %><br>
<%= f.text_field :ship_date, class:"rfq_ship_date"%>
<%= button_tag "1", class: "1day", type:"button" %>
<%= button_tag "2", class: "2day", type:"button" %>
<%= button_tag "3", class: "3day", type:"button" %>
<%= button_tag "4", class: "4day", type:"button" %>
<%= button_tag "5", class: "5day", type:"button" %>
</div>
Any help is appreciated
I think this has already been answered here: Allow only the next 5 business days jquery datepicker
Long story short, if you add "maxDate: '+1w'" as a paramter to the datepicker, while weekends is turned off, it'll automatically select the next 5 days rather than 7 days because it will only count business days.
You can also do a manual check to see if the day you are selecting will be a weekend or holiday. with isWeekend and isHoliday. The code has been shown here: Add days after date is selected excluding weekends and holidays