Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you're using the Validate plugin, you can write a custom rule which reimplements ui.Datepicker's own logic for deciding which dates are selectable or not. I had to write this today and figured someone else could benefit from knowing how:</p> <pre><code>jQuery.validator.addMethod("vdate", function(value, element) { // Datepicker's internal method for choosing selectable ported to a custom validator method. // All criteria are the same, except othermonth is omitted. var inst = $.data(element,'datepicker'); // instance data used internally by datepicker's functions var printDate = $(element).datepicker("getDate"); var minDate = $.datepicker["_getMinMaxDate"](inst, 'min', true); var maxDate = $.datepicker["_getMinMaxDate"](inst, 'max'); var beforeShowDay = $.datepicker["_optionDatepicker"](element,'beforeShowDay'); var daySettings = (beforeShowDay ? beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']); var unselectable = (!daySettings[0] || (minDate !=null &amp;&amp; (printDate &lt; minDate)) || (maxDate !=null &amp;&amp; (printDate &gt; maxDate))); return (this.optional(element) || !unselectable); }, "Please choose a valid date"); </code></pre> <p>This particular addMethod has the advantage of checking each field individually, so if you have multiple datepickers sharing the classname 'vdate' but perhaps having different minDate/maxDate/beforeShowDay settings, Validate will check and follow each datepicker's own rules. </p> <p>Also, if you've written a complicated function for beforeShowDay that excludes weekends, days whose numbers are prime, your wife's birthday, and the last day of every month, so long as it works in ui.Datepicker, Validate will recognize all of them as invalid dates as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload