views:

63

answers:

1

I wonder how to set next month with showing only mondays active:

i tried to do smth like that but it wont work

function onlyMondaysNextMonth(date){
    var day = date.getDay();  
    var mDate = date.getMonth() + 1;

    return {
        minDate: mDate, 
    }     
    return [(day == 1),''];                                                        
}

Thank you.

+1  A: 

Use the following code to enable only Mondays starting from next month

var minDate = null;
var now = new Date();
if (now.getMonth() == 11) {
    minDate = new Date(now.getFullYear() + 1, 0, 1);
} else {
    minDate = new Date(now.getFullYear(), now.getMonth() + 1, 1);
}

/* create datepicker */
jQuery(document).ready(function () {
    jQuery('#datepicker').datepicker({
        minDate: minDate,        
        constrainInput: true,
        beforeShowDay: beforeShowDay
    });
});

function beforeShowDay(date) {
    var day = date.getDay();
    if (day == 1)
        return [true]
    return [false];

}

The working sample is hosted in http://elangovanr.com/samples/jquery/datepickermonday.html for your reference.

Elangovan
Tried your code, but it seems not setting next month to appear. When calendar shows up it just limits days to mondays but we are still in the same month and not next one. Cant we just do smth like that:beforeShowDay: function(date){$(this).datepicker('option', 'minDate', '+1m');var day = date.getDay();if (day == 1) return [true]return [false]; }although it returns too much recursion...
Alex
updated my code. instead of using `getYear` used `getFullYear`
Elangovan
`beforeShowDay` can be simplified to `function beforeShowDay(date) { return [date.getDay() == 1];}`
Justin Johnson
Elan, its look great now! Do you think its possible to detect if there is no active mondays left? Do you know what i mean? I like we are at the end of the month and we passed last monday so there wont be any active monday left. Is there a way to detect that? and pass to next month.
Alex
I am not getting your question, can you explain me with example.
Elangovan
Here is an example, i had to modify it just to show you that we do not need mondays that are already passed so right now is 26 of may meaning the only monday of May left is 31 and it will be active like that http://jsbin.com/udude4/5 but if you are in month that actually wont have active mondays left at the end of the month, like in last month April the last monday was 26th from 31 days meaning if you are in 28, 29 etc there wont be any active mondays and that means we need to pass to next month using your function for instance but to do so we need to detect somehow if there is any active left
Alex
ok, you that can be done. you can find the updated code in http://elangovanr.com/samples/jquery/datepickernew.html
Elangovan
the links seems to be broken
Alex
I am able to open. try now http://elangovanr.com/samples/jquery/datepickernew.html
Elangovan
ok the link is up now. Sorry to be such a pain but it seems that the script wont change the month. I just changed my computer clock to 28/04/2010 and refreshed the page. The calendar will be in april and without active mondays which in that case should switch you to May 1st with active mondays starting from 3th of may. :(
Alex