Anvesh Checka
Anvesh Checka

Reputation: 3835

Make only semimonthly dates in the current month available in jquery datapicker

Only the dates 1 & 16 in any month should be available for selection. All other dates should be disabled. Please help

$(closure.el).find('#listcmd_invoices .add .invoice-from-date-input')
             .datepicker({
                changeYear: true,
                showAnim: 'slide',
                changeMonth : true,
                yearRange : "Y:+2Y",
                beforeShowDay: function(date){
                        return [date.getDate() == 16 && date.getDate() == 1,""]
                    }
             });

Upvotes: 1

Views: 128

Answers (2)

Anvesh Checka
Anvesh Checka

Reputation: 3835

$(closure.el).find('#listcmd_invoices .add .invoice-from-date-input')
         .datepicker({
            changeYear: true,
            showAnim: 'slide',
            changeMonth : true,
            yearRange : "Y:+2Y",
            beforeShowDay: function(date){
                               **if (date.getDate() == 1 || date.getDate() == 16)
                                   return [true,""];
                               else
                                   return [false,""];**
                            }
});

Upvotes: 1

Jamiec
Jamiec

Reputation: 136094

Assuming JQuery-UI datpicker, as that is what you've tagged your question with, the option you should be providing when initializing your datepicker is beforeShowDay. The documentation rovides a fairly good description of what must be returned from the method, reproduced below for clarity:

A function takes a date as a parameter and must return an array with [0] equal to true/false indicating whether or not this date is selectable, [1] equal to a CSS class name or "" for the default presentation, and [2] an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.

So for you, something like:

$( "#datepicker" ).datepicker({
  beforeShowDay: function(date){
    return [
      date.getDate() == 16 || date.getDate() == 1,
      ""
    ];
  }
});

(Just seen your update with code. The only problem you had was your test is "day equals 1 AND day equals 16".. clearly both cant be true. So all you had wrong was you should have used OR!)

Upvotes: 3

Related Questions