A jQuery plugin that attaches a popup calendar to your input fields or shows an inline calendar for selecting individual dates or date ranges. If you find this plugin useful please vote for it on the jQuery site.
This page provides a documentation reference for working with the plugin v3.7.5. Download a copy for your own reference - just add jQuery JavaScript for full functionality.
For version 4.0.0 and later please see the newer documentation reference as that version is a major update to the plugin.
See a demonstration of the datepicker plugin and download the code from there. Or see a minimal page that you could use as a basis for your own investigations.
A separate datepicker instance is created for each targetted control:
$(selector).datepick();
.
When applied to a div
or span
the datepicker
is rendered inline. Otherwise it appears as a popup on demand.
Each instance may have different settings,
e.g. $(selector).datepick({minDate: new Date()});
.
Alternately, you can specify the settings per control by including the
jQuery Metadata
plugin in your page and adding options to the class
attribute,
e.g. <input type="text" class="{minDate: new Date()}"/>
.
Below are the settings that may be applied to each datepicker instance. All are optional.
alignment | altField | altFormat | appendText | autoSize | beforeShow | beforeShowDay | buttonImage | buttonImageOnly | buttonText | calculateWeek | changeFirstDay | changeMonth | changeYear | closeAtTop | constrainInput | defaultDate | duration | gotoCurrent | hideIfNoPrevNext | highlightWeek | mandatory | maxDate | minDate | multiSelect | multiSeparator | navigationAsDateFormat | numberOfMonths | onChangeMonthYear | onClose | onHover | onSelect | rangeSelect | rangeSeparator | selectOtherMonths | shortYearCutoff | showAnim | showBigPrevNext | showCurrentAtPos | showDefault | showOn | showOptions | showOtherMonths | showStatus | showWeeks | statusForDate | stepBigMonths | stepMonths | useThemeRoller | yearRange
Name | Type | Default | Comments |
---|---|---|---|
useThemeRoller | boolean | false | Set to true to use ThemeRoller
CSS classes for styling, or false to use the original plugin CSS classes.
Include a corresponding stylesheet (and ThemeRoller
stylesheets if appropriate) in your page to render the datepicker.Since 3.7.0. |
showOn | string | 'focus' | Control when the datepicker appears. The options are 'focus' for when the input field receives focus, 'button' for when an associated button is clicked, or 'both' for both of the above. This setting is ignored for inline datepickers. |
showAnim | string | 'show' | Specify the animation used when the datepicker is shown and hidden.
The options are 'show' for the standard expand down and to the left,
'fadeIn' for fade in and out, 'slideDown' for expanding downwards,
or any of the jQuery UI effects,
such as 'clip', 'fold', or 'slide', provided you
include the jQuery UI effects module.
Use '' for no animation. Since 3.7.3 - '' for no animation. |
showOptions | object | {} | When using one of the jQuery UI effects as the animation to show
the datepicker, you can pass additional settings to that animation
via this setting. For example, for the 'clip' animation you could
specify horizontal movement: {direction: 'horizontal'} . |
duration | string or number | 'normal' | Set the speed of the animation. The options are 'slow', 'normal', 'fast', or the number of milliseconds. |
buttonText | string | '...' | Provide the text to display on a button to open the datepicker. |
buttonImage | string | '' | To display an image on the trigger button, specify its URL in this setting. |
buttonImageOnly | boolean | false | Indicate whether or not the image (given above) should appear
by itself (true ) or on a button (false ). |
alignment | string | 'bottom' | Set the alignment of the datepicker popup to an edge or corner
of its input field. The options are 'top', 'bottom', 'topLeft',
'topRight', 'bottomLeft', or 'bottomRight'. The first two align left
or right depending on the language direction and available space,
and may swap edges to keep the datepicker in view.
The remainder do not reposition themselves. Since 3.7.0. |
autoSize | boolean | false | Set to true to have the input field automatically sized
for the maximum value under the current
dateFormat .
Leave as false to not resize the input field.Since 3.7.1. |
defaultDate | Date or number or string | null | Specify the date shown when no other date has been selected.
You can provide an actual date via a Date object
(new Date(2009, 1 - 1, 26) ), a date string in the current format,
a number of days before or after today (+7 ), or a string of periods
and units to offset from today ('+1M +10D' ). For the last,
use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.
Upper or lower case may be used.
Leave as null to have the default date be today.Since 3.7.0 - added date string. |
showDefault | boolean | false | When true the default date is set into the
input field whenever no other date has been selected.Since 3.6.0. |
appendText | string | '' | Provide any text that should be displayed after each datepicker input. For example, you may want to describe the date format. |
closeAtTop | boolean | true | Indicate whether the Clear/Close links should appear
at the top of the datepicker (true )
or at the bottom (false ). |
mandatory | boolean | false | Indicate whether or not the date field is mandatory.
If so (true ) the Clear link is hidden. |
hideIfNoPrevNext | boolean | false | Indicate whether the Prev/Next links should be
disabled (false ) or hidden (true )
when they do not apply. |
navigationAsDateFormat | boolean | false | Indicate whether or not the
formatDate
function should be applied to the Prev/Current/Next links.
When true , the function is applied, allowing you to
have these links labelled for the months that they would show. |
showBigPrevNext | boolean | false | Indicate whether or not to show a second set of Prev/Next
links that move by a larger number of months (12 by default, see
stepBigMonths ). |
stepMonths | number | 1 | Specify how many months to move when the Prev/Next links are clicked. |
stepBigMonths | number | 12 | If showing the large Prev/Next links (see
showBigPrevNext ),
specify how many months to move when these are clicked. |
gotoCurrent | boolean | false | Indicate whether the Current link should show the month
for today (false ) or the month for the currently
selected date (true ). |
changeMonth | boolean | true | Indicate whether or not the month may be changed from a drop-down of all the months in the year. You can always use the Prev/Next links. |
changeYear | boolean | true | Indicate whether or not the year may be changed from a drop-down of
possible years. Use the yearRange
setting to control which years appear. |
yearRange | string | '-10:+10' | Specify which years to show in the year drop-down.
The range can be expressed as relative to the currently displayed year
('c-5:c+5'), as relative to today's year ('-10:+10'), as absolute years,
('1980:2010'), or any combination of these ('2000:-5').
Note that this setting only limits the contents of the year drop-down.
Use minDate and/or
maxDate to restrict which dates may be selected.Since 3.7.3 - relative to today's year and combinations. |
changeFirstDay | boolean | false | Indicate whether or not clicking on a day name column header
causes a change to that day as the first of the week. Use the
firstDay
setting to set the first day of the week. |
showOtherMonths | boolean | false | Indicate whether or not to show days from other months that precede
or follow the current month. These dates are not selectable by default -
see selectOtherMonths . |
selectOtherMonths | boolean | false | Indicate whether or not days from other months that precede or follow
the current month are selectable. This setting has no effect unless
showOtherMonths is true .Since 3.5.0. |
highlightWeek | boolean | false | Indicate whether or not to highlight the entire week when hovering over any day in that week. |
showWeeks | boolean | false | Indicate whether or not to add a column showing the week of the year.
The method of calculating a week is determined by the
calculateWeek
setting. Note that the calculation is performed
only for the first day of each week as displayed. |
calculateWeek | function | $.datepick. iso8601Week |
Provide the function that calculates the week of the year for a given date. The function takes a Date as a parameter and returns the number of the week for that date. The default uses the ISO 8601 definition of a week: weeks start on a Monday; the first week of the year contains January 4; up to three days from the previous/next year may be included in the first/last week of the year; weeks are numbered 1 through 53. |
shortYearCutoff | string or number | '+10' | When a two-digit year format is used (see
dateFormat ),
this value helps determine the century for a given date.
If expressed as a number (0 to 99) it is the year beyond which
the century should be the last one instead of the current one.
If expressed as a string, it is converted to a number and added
to the current year before making the comparison above.
If set to -1 the year is always in the 1900s.Since 3.5.2 - disable with -1. |
showStatus | boolean | false | Indicate whether or not to show the status bar at the bottom of the datepicker that contains more detailed explanations of the function of each component. |
statusForDate | function | $.datepick. dateStatus |
Provide a function to construct the status message for a given date.
The function takes the date as a parameter and return a string.
The message may contain HTML markup. The default function uses the
dateStatus
setting for the given date. |
minDate | Date or number or string | null | Specify a lower limit on the dates that may be selected
or leave as null for no such restriction.
You can provide an actual date via a Date object
(new Date(2009, 1 - 1, 26) ), a date string in the current format,
a number of days before or after today (-7 ), or a string of periods
and units to offset from today ('-1M -10D' ). For the last,
use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.
Upper or lower case may be used.Since 3.7.0 - added date string. |
maxDate | Date or number or string | null | Specify an upper limit on the dates that may be selected
or leave as null for no such restriction.
You can provide an actual date via a Date object
(new Date(2009, 1 - 1, 26) ), a date string in the current format,
a number of days before or after today (+7 ), or a string of periods
and units to offset from today ('+1M +10D' ). For the last,
use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.
Upper or lower case may be used.Since 3.7.0 - added date string. |
numberOfMonths | number or number[2] | 1 | Specify the number of months to display in the datepicker.
If expressed as a single number these are shown horizontally.
If expressed as a two-entry array, these are the number of
rows and columns to show, e.g. {numberOfMonths: [2, 3]} . |
showCurrentAtPos | number | 0 | When showing multiple months, use this setting to indicate
in which position the current month should appear,
starting at zero. For example, to show three months with the
current one in the middle:
{numberOfMonths: 3, showCurrentAtPos: 1} . |
rangeSelect | boolean | false | Indicate whether to allow selection of a single date
(false ) or a range of values (true ).
For the latter, the first click selects the starting date
and the second selects the ending date. |
rangeSeparator | string | ' - ' | When selecting date ranges, this setting controls what
separates the two dates in the range when displayed in
the input field or passed to the onSelect
or onClose callbacks. |
multiSelect | number | 0 | To allow selection of multiple individual dates, set this to the
maximum number of allowed selections. The first click on a date
selects it and a second click de-selects it. This setting is ignored if
rangeSelect is true .Since 3.6.0. |
multiSeparator | string | ',' | When selecting multiple individual dates, this setting controls what
separates those dates when displayed in the input field or passed to the
onSelect or
onClose callbacks.Since 3.6.0. |
altField | string or element | '' | As well as the input field and its format (see
dateFormat ),
you can specify an alternate field to also be updated with the
selected date (or range). The setting value is either the
jQuery selector for the field or the element itself. |
altFormat | string | '' | The alternate field above can have its own date format.
You can use these two settings to display the date in one
format to the user, but have a different field carry the
date in a more useable format through for further processing. See the
formatDate
function for the formatting possibilities. |
beforeShow | function | null | Specify a function that is called just before the datepicker
shows itself, allowing you to adjust its settings.
For example, you can use this function to synchronise
two input fields that constitute a date range.
The function takes the input field or division/span to which
the datepicker is attached and the datepicker instance
object as parameters, and returns an object containing
settings that are applied to that instance.$(selector).datepick({beforeShow: setMin});
function setMin(input, inst) {
return {minDate: ...};
} |
beforeShowDay | function | null | Provide a function that is called for each date being displayed.
The function takes a date as a parameter and returns an array
of values where [0] is true if this date is selectable
or false if it is not, [1] is any custom CSS class
name(s) or '' for none, and [2] is an optional tooltip value
for this date. For example, it would return [false, '']
to make the date unselectable, or [true, 'birthday', 'Mum\'s birthday']
to change its appearance via CSS as the 'birthday' class and to
describe whose birthday in a popup tooltip. One standard function is defined:
$.datepick.noWeekends
prevents the selection of any Saturday or Sunday.$(selector).datepick({beforeShowDay: noSundays});
function noSundays(date) {
return [date.getDay() != 0, ''];
} |
onChangeMonthYear | function | null | Specify a function that is called whenever the displayed
month and/or year are changed. The function takes the new year,
new month (1 to 12), the first of that month as a Date, and the current
datepicker instance object as parameters. Within this function,
this refers to the input field for this datepicker.$(selector).datepick(
{onChangeMonthYear: trackMonth});
function trackMonth(year, month, date, inst) {
...
} Since 3.5.2 - added Date type parameter. |
onHover | function | null | Provide a function that is called when the mouse hovers over a day.
The function takes the covered date as a string (in the format given by
dateFormat )
and as a Date, and the current datepicker instance object as parameters.
A second call to the function is made on exit with the date
values set to null . Within this function, this
refers to the input field for this datepicker.$(selector).datepick({onHover: trackDay});
function trackDay(value, date, inst) {
...
} Since 3.5.0. Since 3.5.2 - added Date type parameter. |
onSelect | function | null | Set a function that is called whenever a date is selected
within the datepicker. The function takes the chosen date
as a string (in the format given by
dateFormat )
and as a Date or Date array (for range or multiple selects),
and the current datepicker instance object as parameters.
For date ranges, the function is called for both the start
and end selections and the date string contains both dates
separated by rangeSeparator .
For multiple dates, the function is called for each selection and
de-selection and the date string contains the dates
separated by multiSeparator .
Within this function, this refers to the
input field for this datepicker.$(selector).datepick({onSelect: pickedDate});
function pickedDate(value, date, inst) {
...
} Since 3.5.2 - added Date type parameter. |
onClose | function | null | Provide a function that is called whenever the datepicker
is closed. The function takes the current date
as a string (in the format given by
dateFormat )
and as a Date or Date array (for range multiple selects),
and the current datepicker instance object as parameters.
For date ranges, the date string contains both dates
separated by rangeSeparator .
For multiple dates, the date string contains all the dates
separated by multiSeparator .
Within this function, this refers to the
input field for this datepicker.$(selector).datepick({onClose: closedDate});
function closedDate(value, date, inst) {
...
} Since 3.5.2 - added Date type parameter. |
constrainInput | boolean | true | Indicate whether or not any characters entered directly into the input
field should be restricted to those allowed by the current format (see
dateFormat ). |
Below are the localisation settings that may be applied to each datepicker instance. All are optional. These options are designed to be updated when localising the datepicker for a given language and locale.
Use a localisation package (see the
list on the demo page)
by loading the appropriate file after the datepicker plugin itself.
This adds a language set ($.datepick.regional[langCode]
) and
automatically sets this language as the default for all datepicker fields.
<script type="text/javascript" src="jquery.datepick-fr.js"></script>
Thereafter, if desired, you can restore the original language settings.
$.datepick.setDefaults($.datepick.regional['']);
And then configure the language per datepicker field.
$('#l10nDatepicker').datepick($.datepick.regional['fr']);
clearStatus | clearText | closeStatus | closeText | currentStatus | currentText | dateFormat | dateStatus | dayNames | dayNamesMin | dayNamesShort | dayStatus | firstDay | initStatus | isRTL | monthNames | monthNamesShort | monthStatus | nextBigStatus | nextBigText | nextStatus | nextText | prevBigStatus | prevBigText | prevStatus | prevText | showMonthAfterYear | weekHeader | weekStatus | yearStatus | yearSuffix
Name | Type | Default | Comments |
---|---|---|---|
clearText | string | 'Clear' | The text to display for the link to clear the input field
and close the datepicker. Use the
mandatory
setting to control the link's presence. |
clearStatus | string | 'Erase the current date' | The text to display in the datepicker's status bar for the above link. |
closeText | string | 'Close' | The text to display for the link to close the datepicker without changing the field value. |
closeStatus | string | 'Close without change' | The text to display in the datepicker's status bar for the above link. |
prevText | string | '<Prev' | The text to display for the link to move to the previous month.
Use the stepMonths
setting to specify how many months to move at one time. |
prevStatus | string | 'Show the previous month' | The text to display in the datepicker's status bar for the above link. |
prevBigText | string | '<<' | The text to display for the link to move to the previous year.
Use the stepBigMonths
setting to specify how many months to move at one time and the
showBigPrevNext
setting to control its presence. |
prevBigStatus | string | 'Show the previous year' | The text to display in the datepicker's status bar for the above link. |
nextText | string | 'Next>' | The text to display for the link to move to the next month.
Use the stepMonths
setting to specify how many months to move at one time. |
nextStatus | string | 'Show the next month' | The text to display in the datepicker's status bar for the above link. |
nextBigText | string | '>>' | The text to display for the link to move to the next year.
Use the stepBigMonths
setting to specify how many months to move at one time and the
showBigPrevNext
setting to control its presence. |
nextBigStatus | string | 'Show the next year' | The text to display in the datepicker's status bar for the above link. |
currentText | string | 'Today' | The text to display for the link to show the month containing today.
Use the gotoCurrent
setting to show the month of the current selection instead. |
currentStatus | string | 'Show the current month' | The text to display in the datepicker's status bar for the above link. |
monthNames | string[12] | ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | The names of the months. These are used for display in the month selection drop-down, as well as for formatting and parsing dates. |
monthNamesShort | string[12] | ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | The abbreviated names of the months for formatting and parsing dates. |
monthStatus | string | 'Show a different month' | The text to display in the datepicker's status bar
for the month selection drop-down. Use the
changeMonth
setting to allow the month to be changed with this drop-down. |
yearStatus | string | 'Show a different year' | The text to display in the datepicker's status bar
for the year selection drop-down. Use the
changeYear
setting to allow the year to be changed with this drop-down. |
weekHeader | string | 'Wk' | The text to display in the header for the week-of-the-year column. Use the
showWeeks
setting to control this column's presence. |
weekStatus | string | 'Week of the year' | The text to display in the datepicker's status bar for the week-of-the-year column. |
dayNames | string[7] | ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] | The names of the days, starting at Sunday. These are used for formatting and parsing dates and in various status bar messages. |
dayNamesShort | string[7] | ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] | The abbreviated names of the days, starting at Sunday. These are used for formatting and parsing dates and in various status bar messages. |
dayNamesMin | string[7] | ['Su','Mo','Tu','We','Th','Fr','Sa'] | The minimal names of the days for display as column headings. Use the
firstDay
setting to specify the first day of the week and the
changeFirstDay
setting to allow the user to change it themselves. |
dayStatus | string | 'Set DD as first week day' | The text to display in the datepicker's status bar for the day column headers. 'D' is replaced by the abbreviated day name and 'DD' is replaced by the full day name. |
dateStatus | string | 'Select DD, M d' | The text to display in the datepicker's status bar for the
selectable days in a month. The
formatDate
function is applied to the text before display.
This setting is used by the standard implementation
(dateStatus )
of the statusForDate
callback. |
dateFormat | string | 'mm/dd/yy' | The format in which dates are presented in the input field.
See the formatting possibilities in the
formatDate
function. |
firstDay | number | 0 | The first day of the week: 0 is Sunday, 1 is Monday, through to 6 is Saturday. |
initStatus | string | 'Select a date' | The text to display in the datepicker's status bar when no other status bar message applies. |
isRTL | boolean | false | Set to true to indicate that this localisation's
language reads right-to-left. This affects the positioning
of various elements as well as the text itself. |
showMonthAfterYear | boolean | false | Indicate whether the month drop-down should appear after
(true ) the year drop-down, or before it (false ).Since 3.5.2 - moved to localisation settings. |
yearSuffix | string | '' | Text to append to the year in each month's header. Since 3.5.2. |
Below are the fields and functions available from the datepicker
manager ($.datepick
).
Name | Type | Default | Comments |
---|---|---|---|
regional | object[] | The set of localisation settings for the datepicker.
Entries are indexed by the country/region code with '' providing the default
(English) settings. Each entry is an object with the properties listed
on the Localisation tab.
Language packages load new entries into this array and
automatically apply them as global defaults. If necessary,
you can then revert to the default language settings with$.datepick.setDefaults($.datepick.regional['']); and apply the language settings to individual fields with $('#frenchDatepick').datepick($.datepick.regional['fr']); .Check out the list of available localisation packages. | |
ATOM | string | 'yy-mm-dd' | RFC 3339 (ISO 8601) This and the fields below are designed to be used for the dateFormat and
altFormat settings,
as well as with the formatDate and
parseDate functions. |
COOKIE | string | 'D, dd M yy' | |
ISO_8601 | string | 'yy-mm-dd' | |
RFC_822 | string | 'D, d M y' | |
RFC_850 | string | 'DD, dd-M-y' | |
RFC_1036 | string | 'D, d M y' | |
RFC_1123 | string | 'D, d M yy' | |
RFC_2822 | string | 'D, d M yy' | |
RSS | string | 'D, d M y' | RFC 822 |
TICKS | string | '!' | Since 3.5.2. |
TIMESTAMP | string | '@' | |
W3C | string | 'yy-mm-dd' | ISO 8601 |
dateStatus | destroy | dialog | disable | enable | errorPlacement | formatDate | getDate | hide | isDisabled | iso8601Week | noWeekends | option | parseDate | refresh | setDate | setDefaults | show
Signature | Returns | Comments |
---|---|---|
$.datepick.setDefaults(settings) | void | Update the default instance settings (see
Settings and
Localisation tabs)
to use with all datepicker instances.
|
$(selector).datepick('option', settings) | jQuery object | Update the settings for the datepicker instances attached to the
given controls.settings (object) is the set of changed options
|
$(selector).datepick('option', name, value) | jQuery object | Update the setting for a single property on the datepicker instances
attached to the given controls.name (string) is the name of the optionvalue (any) is the new value of the option
|
$(selector).datepick('option', name) | any | Retrieve the datepicker instance setting(s) from the first of the given
controls. All settings are returned as an object if a name of 'all' is provided.
All global default settings are returned as an object if the name is 'defaults'.
If there is no appropriate setting, null is returned.name (string) is the name of an individual setting,
'all' for all instance settings, or 'defaults' for all global defaults
Since 3.5.2. |
$(selector).datepick('dialog', date, onSelect, settings, pos) | jQuery object | Display the datepicker in a "dialog" box.date (string or Date) is the initial date
to display (in the current format)onSelect (function) is the
function
to call when a date is selectedsettings (object, optional) is any additional options
for the dialog date picker instancepos (int[2], optional) is left and top coordinates
for the dialog's position within the screen or (event) an event
with x/y coordinates or omitted for the screen centre
Since 3.7.0 - initial date as Date . |
$(selector).datepick('destroy') | jQuery object | Remove the datepicker functionality from the given controls. |
$(selector).datepick('enable') | jQuery object | Enable the datepickers for the given controls. |
$(selector).datepick('disable') | jQuery object | Disable the datepickers for the given controls. |
$(selector).datepick('isDisabled') | boolean | Returns true if the first datepicker selected is currently
disabled or false if it is enabled. |
$(selector).datepick('show') | jQuery object | Open the datpicker for the specified field. |
$(selector).datepick('hide') | jQuery object | Close the datepicker for the specified field. |
$(selector).datepick('refresh') | jQuery object | Redraw the datepickers for the given controls. You shouldn't need to invoke this command as the datepicker refreshes when its options are changed. But just in case... |
$(selector).datepick('setDate', date, endDate) | jQuery object | Set the current date for the datepickers for the given controls.date (Date, optional) is the new selected date
or (Date[]) for the start and end of a range or multiple
individual dates - omit to clear all datesendDate (Date, optional) is the end date for a
date range -
it is ignored if not selecting a range, and defaults to the start date
if omitted otherwiseFor each parameter, you can provide an actual date via a Date object ( new Date(2009, 1 - 1, 26) ), a date string in the current format,
a number of days before or after today (+7 ), or a string of periods
and units to offset from today ('+1M +10D' ). For the last,
use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.
Upper or lower case may be used. Prefix the string with 'C' to
calculate from the currently selected date rather than today.
Since 3.7.0 - added date string. Since 3.7.1 - added relative to current. Since 3.7.2 - omit dates to clear all dates. |
$(selector).datepick('getDate') | Date or Date[] | For the first element selected, retrieve the currently selected date, or null if no date has been chosen yet. If selecting a date range the start and end dates are returned in an array. If selecting multiple dates the dates are returned in an array. |
$.datepick.dateStatus(date, inst) | string | Returns the default status bar entry when hovering over a date.
It applies the
dateStatus
setting to the current date. You can change the way the status text
for a date is determined by providing your own function for the
statusForDate
setting. |
$.datepick.iso8601Week(date) | number | Calculate the week of the year for the given date based on the
ISO 8601 definition.
You can change the way the week of the year is calculated
by providing your own function for the
calculateWeek
setting. |
$.datepick.noWeekends(date) | array | A function that can be used for the
beforeShowDay
setting that does not allow selection of days on weekends. |
$.datepick.formatDate(format, date, settings) | string | Convert a Date value into a string following a given format.format (string) is the format for display - any combination of:
date (Date) is the date to displaysettings (object, optional) is any additional settings for the
conversion - this object may contain the following attributes (all optional):dayNames (string[7]) is the full names
of the days starting from Sunday;dayNamesShort (string[7]) is the abbreviated names
of the days starting from Sunday;monthNames (string[12]) is the full names of the months;monthNamesShort (string[12]) is the abbreviated names of the months;calculateWeek (function) is a function to calculate
the week of the year (see iso8601Week) -
if any of these are omitted, the corresponding value from the
datepicker defaults is used instead
Since 3.5.2 - added Windows ticks. Since 3.7.0 - added week of the year. |
$.datepick.parseDate(format, value, settings) | Date | Convert a string value into a Date object following a given format.
Various exceptions may be thrown if error conditions are encountered.format (string) is the format that describes the expected date -
see the possibilities under the formatDate function.value (string) is the date text to convertsettings (object, optional) is any additional settings for the
conversion - this object may contain the following attributes (all optional):shortYearCutoff (number) is the cutoff year for determining the century;dayNames (string[7]) is the full names of the days from Sunday;dayNamesShort (string[7]) is the abbreviated names of the days from Sunday;monthNames (string[12]) is the full names of the months;monthNamesShort (string[12]) is the abbreviated names of the months -
if any of these are omitted, the corresponding value from the
datepicker defaults is used instead
|
$.datepick.errorPlacement(error, element) | void | Correctly places a validation error message after any trigger button or icon.
It should be assigned as the errorPlacement setting for the
validate call.Since 3.5.1 - only available with the validation extension. |
Datepicker can be integrated with Jörn Zaefferer's
validation plugin by
adding the jquery.datepick-validation.js
extension to your page.
Since 3.5.1.
Four new validations are defined, as listed below. All automatically handle date ranges
(including checking that the start date is not after the end date) and multiple dates.
The first may be added as a class to your datepicker fields, while the others must
be defined in the validate
settings and be passed an empty array.
dpDate
- basic format validationdpMinDate
- validation against a minimum date limit onlydpMaxDate
- validation against a maximum date limit onlydpMinMaxDate
- validation against minimum and maximum date limitsThere is also a custom errorPlacement
function defined so that
the error messages appear after any trigger button or icon.
You can customise the error messages via the datepicker defaults:
$.datepick.setDefaults({...})
.
The message fields are validateDate
, validateDateMin
,
validateDateMax
, and validateDateMinMax
.
Within the latter use '{0}' and/or '{1}' for substituting in
minimum/maximum date values.
The sample page below show how the validations would be used.
It defines three datepicker fields: one plain, one a date range, and
one with a maximum limit. The validations are applied to the first two
by including the dpDate
class on the fields.
For the last one the validation is defined in the validate
call on the form, linking the field to the dpMaxDate
rule.
Also note that a custom message is defined for the date range field.
<head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="jquery.datepick.js"></script>
<script type="text/javascript" src="jquery.datepick-validation.js"></script>
<script type="text/javascript">
$(function() {
$('#favDate').datepick();
$('#holidayDates').datepick({rangeSelect: true});
$('#birthDate').datepick({maxDate: new Date()});
$('#validateForm').validate({
errorPlacement: $.datepick.errorPlacement,
rules: {
birthDate: {dpMaxDate: []}
},
messages: {
holidayDates: 'Please enter a valid date range'}
});
});
</script>
<style type="text/css">@import "jquery.datepick.css";</style>
</head>
<body>
<form id="validateForm">
<p>Favourite date: <input type="text" id="favDate"
name="favDate" size="10" class="dpDate"/></p>
<p>Period of last holiday: <input type="text" id="holidayDates"
name="holidayDates" size="24" class="dpDate"/></p>
<p>Date of birth: <input type="text" id="birthDate"
name="birthDate" size="10"/></p>
</form>
</body>
Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.