Datepicker Widgetversion added: 1.0
Description: Select a date from a popup or inline calendar
Options
altFieldType: Selector or jQuery or Element
""
altFormat
option to change the format of the date within this field. Leave as blank for no alternate field.altFormatType: String
""
dateFormat
to be used for the altField
option. This allows one date format to be shown to the user for selection purposes, while a different format is actually sent behind the scenes. For a full list of the possible formats see the [[UI/Datepicker/formatDate|formatDate]] functionappendTextType: String
""
autoSizeType: Boolean
false
true
to automatically resize the input field to accommodate dates in the current dateFormat
.beforeShowType: Function( Element input, Object inst )
null
beforeShowDayType: Function( Date date )
null
[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.calculateWeekType: Function()
jQuery.datepicker.iso8601Week
changeMonthType: Boolean
false
changeYearType: Boolean
false
yearRange
option to control which years are made available for selection.closeTextType: String
"Done"
showButtonPanel
option to display this button.constrainInputType: Boolean
true
true
, entry in the input field is constrained to those characters allowed by the current dateFormat
option.currentTextType: String
"Today"
showButtonPanel
option to display this button.dateFormatType: String
"mm/dd/yy"
[[UI/Datepicker/formatDate|formatDate]]
function.dayNamesType: Array
[ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
dateFormat
option.dayNamesMinType: Array
[ "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ]
dayNamesShortType: Array
[ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
dateFormat
option.defaultDateType: Date or Number or String
null
[[UI/Datepicker#option-dateFormat|dateFormat]]
, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.- Date: A date object containing the default date.
-
Number: A number of days from today. For example
2
represents two days from today and-1
represents yesterday. -
String: A string in the format defined by the
dateFormat
option, or a relative date. Relative dates must contain value and period pairs; valid periods are"y"
for years,"m"
for months,"w"
for weeks, and"d"
for days. For example,"+1m +7d"
represents one month and seven days from today.
durationType: or String
"normal"
gotoCurrentType: Boolean
false
true
, the current day link moves to the currently selected date instead of today.hideIfNoPrevNextType: Boolean
false
maxDateType: Date or Number or String
null
null
, there is no maximum.- Date: A date object containing the maximum date.
-
Number: A number of days from today. For example
2
represents two days from today and-1
represents yesterday. -
String: A string in the format defined by the
dateFormat
option, or a relative date. Relative dates must contain value and period pairs; valid periods are"y"
for years,"m"
for months,"w"
for weeks, and"d"
for days. For example,"+1m +7d"
represents one month and seven days from today.
minDateType: Date or Number or String
null
null
, there is no minimum.- Date: A date object containing the minimum date.
-
Number: A number of days from today. For example
2
represents two days from today and-1
represents yesterday. -
String: A string in the format defined by the
dateFormat
option, or a relative date. Relative dates must contain value and period pairs; valid periods are"y"
for years,"m"
for months,"w"
for weeks, and"d"
for days. For example,"+1m +7d"
represents one month and seven days from today.
monthNamesType: Array
[ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
dateFormat
option.monthNamesShortType: Array
[ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
dateFormat
option.nextTextType: String
"Next"
numberOfMonthsType: Number or Array
1
- Number: The number of months to display in a single row.
- Array: An array defining the number of rows and columns to display.
onChangeMonthYearType: Function( Integer year, Integer month, Object inst )
null
this
refers to the associated input field.onCloseType: Function( String dateText, Object inst )
null
""
if none) and the datepicker instance as parameters. this
refers to the associated input field.onSelectType: Function( String dateText, Object inst )
null
this
refers to the associated input field.prevTextType: String
"Prev"
selectOtherMonthsType: Boolean
false
showOtherMonths
option is set to true
.shortYearCutoffType: Number or String
"+10"
[[UI/Datepicker#option-dateFormat|dateFormat]]
'y'). Any dates entered with a year value less than or equal to the cutoff year are considered to be in the current century, while those greater than it are deemed to be in the previous century.-
Number: A value between
0
and99
indicating the cutoff year. -
String: A relative number of years from the current year, e.g.,
"+3"
or"-5"
.
showAnimType: String
"show"
"show"
(the default), "slideDown"
, "fadeIn"
, any of the jQuery UI effects. Set to an empty string to disable animation.showCurrentAtPosType: Number
0
numberOfMonths
option, the showCurrentAtPos
option defines which position to display the current month in.showMonthAfterYearType: Boolean
false
showOnType: String
"focus"
"focus"
), when a button is clicked ("button"
), or when either event occurs ("both"
).showOptionsType: Object
{}
showAnim
option, you can provide additional settings for that animation via this option.showOtherMonthsType: Boolean
false
selectOtherMonths
option.showWeekType: Boolean
false
true
, a column is added to show the week of the year. The calculateWeek
option determines how the week of the year is calculated. You may also want to change the firstDay
option.stepMonthsType: Number
1
weekHeaderType: String
"Wk"
showWeek
option to display this column.yearRangeType: String
"c-10:c+10"
"-nn:+nn"
), relative to the currently selected year ("c-nn:c+nn"
), absolute ("nnnn:nnnn"
), or combinations of these formats ("nnnn:-nn"
). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate
and/or maxDate
options.Methods
destroy()
dialog( date [, onSelect ] [, settings ] [, pos ] )
-
dateThe initial date.
-
onSelectType: Function()A callback function when a date is selected. The function receives the date text and date picker instance as parameters.
-
settingsType: OptionsThe new settings for the date picker.
-
posType: Number[2] or MouseEventThe position of the top/left of the dialog as
[x, y]
or aMouseEvent
that contains the coordinates. If not specified the dialog is centered on the screen.
getDate() Returns: Date
null
if no date has been selected.hide()
isDisabled() Returns: Boolean
refresh()
setDate( date )
Date
object or a string in the current date format (e.g., "01/26/2009"
), a number of days from today (e.g., +7
) or a string of values and periods ("y"
for years, "m"
for months, "w"
for weeks, "d"
for days, e.g., "+1m +7d"
), or null
to clear the selected date.-
dateType: DateThe new date.
show()
The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily.
By default, the datepicker calendar opens in a small overlay when the associated text field gains focus. For an inline calendar, simply attach the datepicker to a div or span.
Keyboard interaction
While the datepicker is open, the following key commands are available:
- PAGE UP: Move to the previous month.
- PAGE DOWN: Move to the next month.
- CTRL+PAGE UP: Move to the previous year.
- CTRL+PAGE DOWN: Move to the next year.
- CTRL+HOME: Move to the current month. Open the datepicker if closed.
- CTRL+LEFT: Move to the previous day.
- CTRL+RIGHT: Move to the next day.
- CTRL+UP: Move to the previous week.
- CTRL+DOWN: Move the next week.
- ENTER: Select the focused date.
- CTRL+END: Close the datepicker and erase the date.
- ESCAPE: Close the datepicker without selection.
Utility functions
- $.datepicker.setDefaults( settings ) - Set settings for all datepicker instances.
- $.datepicker.formatDate( format, date, settings ) - Format a date into a string value with a specified format.
- $.datepicker.parseDate( format, value, settings ) - Extract a date from a string value with a specified format.
- $.datepicker.iso8601Week( date ) - Determine the week of the year for a given date: 1 to 53.
- $.datepicker.noWeekends - Set as beforeShowDay function to prevent selection of weekends.
Localization
Datepicker provides support for localizing its content to cater for different languages and date formats. Each localization is contained within its own file with the language code appended to the name, e.g., jquery.ui.datepicker-fr.js
for French. The desired localization file should be included after the main datepicker code. Each localization file adds its settings to the set of available localizations and automatically applies them as defaults for all instances.
The $.datepicker.regional
attribute holds an array of localizations, indexed by language code, with ""
referring to the default (English). Each entry is an object with the following attributes: closeText
, prevText
, nextText
, currentText
, monthNames
, monthNamesShort
, dayNames
, dayNamesShort
, dayNamesMin
, weekHeader
, dateFormat
, firstDay
, isRTL
, showMonthAfterYear
, and yearSuffix
.
You can restore the default localizations with:
$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
And can then override an individual datepicker for a specific locale:
$( selector ).datepicker( $.datepicker.regional[ "fr" ] );
Additional Notes:
- This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point.
Example:
A simple jQuery UI Datepicker.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!doctype html> < html lang = "en" > < head > < meta charset = "utf-8" > < title >datepicker demo</ title > </ head > < body > < div id = "datepicker" ></ div > < script > $( "#datepicker" ).datepicker(); </ script > </ body > </ html > |