obviously I dont know much about JS so I try best to run the datepicker. In our picker, we wanted only be able to pick every last Friday of the month. I've already written the code for this and it should fit:
$(function() {
$( "#datepicker" ).datepicker({
var day = date.getDay();
return [( (day==5 && date.getDate() > 23)), ''];
Now I would have to integrate this into my existing function. It doesn't work the way I've tried. Where is the mistake?
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: 'dd/mm/yy',
closeText:"Schließen",
prevText:"Vorheriger",
nextText:"Nächster;",
currentText:"Heute",
monthNames: ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],
monthNamesShort:["Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],
dayNames:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],
dayNamesShort:["So","Mo","Di","Mi","Do","Fr","Sa"],
dayNamesMin:["So","Mo","Di","Mi","Do","Fr","Sa"],
weekHeader:"Sm",
firstDay:1
});
Hope you understand my problem and be able help me.
Thanks a lot!
CodePudding user response:
Set the corresponding callback using the beforeShowDay
key to the object passed to the datepicker
function:
( Note: I have also updated the algorithm because under some circumstances (July 2020, Dec 2021) it would pick the two last Fridays and under some other (Feb 2019) it would not pick any Friday )
$( "#datepicker" ).datepicker({
...
beforeShowDay: (date)=>{
var monthDays = new Date(date.getFullYear(),date.getMonth() 1,0).getDate();
var day = date.getDay();
return [( (day==5 && date.getDate() > monthDays - 7 )), ''];
}
}