Sunday only on Jquery Datepicker? - javascript

AIM: TO only allow users to select sunday on the datpicker calendar.
Currently I have it almost done, except for some reason every other day except Sunday works. When I use 7 for Sunday in the code below the entire calendar is unclickable, any other day works perfect.
$(document).ready(function() {
$("#datepicker2").datepicker({
autoSize: true, // automatically resize the input field
altFormat: 'yy-mm-dd', // Date Format used
firstDay: 1, // Start with Monday
beforeShowDay: function(date)
{ return [date.getDay() == 7,''];}}); // Allow only one day a week
});
Question: How can I only allow Sunday selection?

Date.getDay() returns a value in the range 0-6, not 1-7.
beforeShowDay: function(date) {
return [date.getDay() === 0,''];
}

Related

How do I disable weekends and specific dates in this code for date picker?

I am using a plugin on woocommerce and I need to disable sundays and some specific dates (Xmas holidays) on date picker. Your help is much appreciated.
I have managed to disable the today date but I am struggling to do the rest.
Also is there a way of adding a if statement that if time is > 17:00 automatically datepicker changes to +2 days and else just +1?
(function( $ ) { $(function() {
if ($('.pcfme-datepicker').length) {
$('.pcfme-datepicker').datepicker({
dateFormat : 'dd-mm-yy'
});
}
var dateToday = new Date();
dateToday.setDate(dateToday.getDate() + 1);
if ($('.pcfme-datepicker-disable-past').length) {
$('.pcfme-datepicker-disable-past').datepicker({
dateFormat : 'dd-mm-yy',
minDate: dateToday
});
}
});

Jquery Datepicker - disable tomorrow and if Time after 9 pm disable day after tomorrow

Working on order system, and i want user to order from next day(tomorrow) and if today is after 9:00PM, user should order from next to next day(day after tomorrow), I am using Jquery Datepicker
Below is myscript with no weekends
$(".datepicker").datepicker({
dateFormat: "dd-mm-yy",
beforeShowDay: $.datepicker.noWeekends
});
You can try this:
var today = new Date();
$(".datepicker").datepicker({
dateFormat: "dd-mm-yy",
minDate: today.getHours() >= 21 ? 2 : 1
});
Here is the DEMO.

how to disable all dates except Wednesday and Sunday dates in Jquery Ui Datepicker

I am using Jquery Ui Datepicker. I want to disable all dates except Wednesday and Sunday Dates. I wrote code like below. But it works only for Wednesday dates. And it displays from next month Onwards.I want it enable current month also.
<script>
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: 'dd-mm-yy',
minDate: 1,
beforeShowDay: enableWednesday,
});
});
function enableWednesday(date) {
var day = date.getDay();
return [(day == 3), ''];
}
</script>
Please help me to enable all Wednesday and Sunday dates for current month also.Thanks in advance
Try this code
$(function(){
$("#datepicker").datepicker(
{
beforeShowDay: function (date) {
if (date.getDay() == 0 || date.getDay() == 3) {
return [true, ''];
}
return [false, ''];
}
});
});
Please refer the following url Disable specific days of the week on jQuery UI datepicker

Display specific days of the week UI datepicker

I would like to disable certain days like every monday or every tuesday or every monday, thursday friday, etc. on a jQuery UI datepicker.
I tried a lot of code without result. Anyone can help me!
My current code is as below:
<script type="text/javascript">
$(function() {
var $hiddenInput = $('#travelDate');
$('#datepicker').datepicker({dateFormat: 'yy-mm-dd'});
$("#datepicker").datepicker("option", "minDate", 2);
$('#datepicker').datepicker({
inline: true
});
// this code not working for my example
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 1 && day != 2), ''];
}
});
$(document).on("change", "#datepicker", function () {
$hiddenInput.val($(this).val());
})
});
</script>
You're initializing the datepicker more than once. This is causing the problems. Consolidate your options into one options object and everything works fine:
$("#datepicker").datepicker({
inline: true,
minDate: 2,
dateFormat: 'yy-mm-dd',
beforeShowDay: function (date) {
var day = date.getDay();
return [(day != 1 && day != 2), ''];
}
});
Example: http://jsfiddle.net/WP29E/54/

datepicker beforeShowDay return 3 months

I need to disable some day in jquery datepicker calendar, so in the function beforeShowDay I write this:
beforeShowDay: function(date){
if(parseInt(calMonth) != parseInt(date.getMonth())){
calMonth = date.getMonth();
alert(calMonth + ' - ' + date.getMonth());
}
return {0: true};
}
where calMonth contains the current month number. Now if I run this, I get 3 alert that show in order:
9-9, than 10-10 and than 11-11. Why I have 3 message, while it shouldn't show me anything (because when I open datepicker it shows by default the calendar of current month, so if(parseInt(calMonth) != parseInt(date.getMonth())) should return false.
I also set numberOfMonths: 1.
Had the same problem, this is how i fixed:
$("#datepicker").datepicker({ showWeek: true, showOtherMonths : false,
//I'm using onChangeMonthYear to always keep my datepicker month updated
onChangeMonthYear: function(year, month, inst){
$(this).datepicker( "setDate", month + '/1/' + year );
},
beforeShowDay: function(date) {
//Now I can get only the days of the current selected month, and do whatever I want...
if(date.getMonth()==$(this).datepicker('getDate').getMonth())
console.log(date.getDate()+' - '+date.getMonth()+' - '+$(this).datepicker('getDate').getMonth());
//keep returning as usual to the datepicker
return [true, ''];
}
});
Hope it helps =)

Categories

Resources