How can I open jppery datepicker from next month when there are no days in that month?

I am using jquery datepicker with a filter beforeShowDay

that only allows Tuesdays. If I'm near the end of the month and there are no more Tuesdays, the picker will open in the current month without a date.

How to find out this situation using the collector? Is there a way to query the available dates for a selected month or something?

If I really acknowledge this situation, how do I get the picker to open next month when the user clicks?

Is there an automatic way to do this?

+3


source to share


3 answers


Try the jsfiddle I made.



$(document).ready( function() {
    $('#datepicker').datepicker({
        defaultDate: nextTuesday(),
        beforeShowDay: enableTuesdays
    });
});

function enableTuesdays(date) {
    // 0 =s unday, 1 = monday, 2 = tuesday, 3 = wednesday,
        // 4 = thursday, 5 = friday, 6 = saturday
    var day = date.getDay();
    return [(day == 2), ''];
}

function nextTuesday() {
    var today = new Date();
    var offset = (today.getDay() < 2) ? 0 : 7;
    var daysUntilTuesday = 2 + offset - today.getDay();
    return '+'+daysUntilTuesday;
}

      

+3


source


Use the datepicker method setDate()

- http://jqueryui.com/demos/datepicker/#method-setDate - to set the calendar date to the next available Tuesday in the beforeShowDay

event.



Below is an example of the next next day of the week: Get the date of a specific day of the week in JavaScript

0


source


While this is not relevant to figuring out the logic for closing a calendar with the next month if there are no more dates available. If the front-end allows it, you can open a datepicker with a 2 month view so you always have dates to choose from?

The installer will require you to pass 'numberOfMonths' as an option when initializing the datepicker.

$('#datepicker').datepicker({ numberOfMonths: 2 });

      

0


source







All Articles