[ui.datepicker.js] Patch for making only particular days selectable

[ui.datepicker.js] Patch for making only particular days selectable


Hello,
I am submitting this patch, if anyone's interested. I needed that
functionality in one of my projects and I found it wasn't possible.
This patch is for version 1.7.2.
--- ui.datepicker.js    2009-06-12 03:20:44.000000000 +0200
+++ ui.datepicker.js    2009-09-25 09:57:34.000000000 +0200
@@ -98,7 +98,8 @@
        altField: '', // Selector for an alternate field to store selected
dates into
        altFormat: '', // The date format to use for the alternate field
        constrainInput: true, // The input is constrained by the current
date format
-        showButtonPanel: false // True to show button panel, false to not
show it
+        showButtonPanel: false, // True to show button panel, false to not
show it
+        onlyDates: null // If defined, only these dates are selectable
    };
    $.extend(this._defaults, this.regional['']);
    this.dpDiv = $('<div id="' + this._mainDivId + '" class="ui-
datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-
all ui-helper-hidden-accessible"></div>');
@@ -1255,6 +1256,20 @@
            inst.currentYear, inst.currentMonth, inst.currentDay)));
            return startDate;
    },
+
+    _isInOnlyDays: function(inst, date) {
+        var onlyDates = this._get(inst, 'onlyDates');
+        if (onlyDates == null)
+            return true;
+        var e;
+        for (var i in onlyDates) {
+            e = new Date(onlyDates[i]);
+            if (e.getDate() == date.getDate() && e.getMonth() == date.getMonth
() && e.getYear() == date.getYear())
+                return true;
+
+        }
+        return false;
+    },
    /* Generate the HTML for the current state of the date picker. */
    _generateHTML: function(inst) {
@@ -1375,7 +1390,7 @@
                            beforeShowDay.apply((inst.input ? inst.input[0] : null),
[printDate]) : [true, '']);
                        var otherMonth = (printDate.getMonth() != drawMonth);
                        var unselectable = otherMonth || !daySettings[0] ||
-                            (minDate && printDate < minDate) || (maxDate && printDate >
maxDate);
+                            (minDate && printDate < minDate) || (maxDate && printDate >
maxDate) || !this._isInOnlyDays(inst, printDate);
                        tbody += '<td class="' +
                            ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' :
'') + // highlight weekends
                            (otherMonth ? ' ui-datepicker-other-month' : '') + //
highlight days from other months