-1

Is there a way to disable days from jquery UI datepicker?

I tried to use dateformat mm/yy to limit days, but my boss is still concerned that user still assume they need to choose a day

$("#date").datepicker({ yearRange: '1950:2015', changeYear: true, changeMonth: true });

I want to disable "day" and in my situation, if possible I prefer to use datepicker instead of two dropdownlists.

I saw there are some articles talking about disable specified days http://davidwalsh.name/jquery-datepicker-disable-days

so I think there maybe a way to disable all days

pita
  • 537
  • 4
  • 15
  • 35
  • 1
    Can you show a tiny snippet of code? That tends to make people more interested in the problem. Also, links to existing websites or photos of the situation sometimes help. – john_science Mar 27 '12 at 19:00
  • 1
    Check this one out: http://stackoverflow.com/questions/2208480/jquery-date-picker-to-show-month-year-only – Steen Mar 27 '12 at 19:02
  • 2
    If you don't want to pick a date, why are you using the datepicker? Use a pair of dropdowns to select year and month instead. – Blazemonger Mar 27 '12 at 19:05

1 Answers1

0

Yes, use the beforeShowDay event handler on the datepicker's configuration object ...

function restrictdays(date) {
    /* logic here */

    return [
        /* boolean indicating whether date is valid */
        isvalid,
        /* css class name */
        isvalid ? 'success' : 'failure',
        /* optional tooltip */
        isvalid ? 'good job' : 'bad job'
    ]; 
}


$(function() {
  $('#date').datepicker({
    /* ... config options ... */
    beforeShowDay: restrictdays
  });
});

Reference

Alex
  • 34,899
  • 5
  • 77
  • 90
  • The 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(s) 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. – ecoologic Apr 02 '12 at 20:00