options.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. Options
  2. =======
  3. All options that take a "Date" can handle a ``Date`` object; a String formatted according to the given ``format``; or a timedelta relative to today, eg "-1d", "+6m +1y", etc, where valid units are "d" (day), "w" (week), "m" (month), and "y" (year). Use "0" as today.
  4. There are also aliases for the relative timedelta's: "yesterday" equals "-1d", "today" is equal to "+0d" and "tomorrow" is equal to "+1d".
  5. Most options can be provided via data-attributes. An option can be converted to a data-attribute by taking its name, replacing each uppercase letter with its lowercase equivalent preceded by a dash, and prepending "data-date-" to the result. For example, ``startDate`` would be ``data-date-start-date``, ``format`` would be ``data-date-format``, and ``daysOfWeekDisabled`` would be ``data-date-days-of-week-disabled``.
  6. See the `quick reference`_ for an overview of all options and their default values
  7. autoclose
  8. ---------
  9. Boolean. Default: false
  10. Whether or not to close the datepicker immediately when a date is selected.
  11. assumeNearbyYear
  12. ----------------
  13. Boolean or Integer. Default: false
  14. If true, manually-entered dates with two-digit years, such as "5/1/15", will be parsed as "2015", not "15". If the year is less than 10 years in advance, the picker will use the current century, otherwise, it will use the previous one. For example "5/1/15" would parse to May 1st, 2015, but "5/1/97" would be May 1st, 1997.
  15. To configure the number of years in advance that the picker will still use the current century, use an Integer instead of the Boolean true. E.g. "assumeNearbyYear: 20"
  16. beforeShowDay
  17. -------------
  18. Function(Date). Default: $.noop
  19. A function that takes a date as a parameter and returns one of the following values:
  20. * undefined to have no effect
  21. * A Boolean, indicating whether or not this date is selectable
  22. * A String representing additional CSS classes to apply to the date's cell
  23. * An object with the following properties:
  24. * ``enabled``: same as the Boolean value above
  25. * ``classes``: same as the String value above
  26. * ``tooltip``: a tooltip to apply to this date, via the ``title`` HTML attribute
  27. * ``content``: the content to display in the day cell, rather than the default (day of month as text)
  28. beforeShowMonth
  29. ---------------
  30. Function(Date). Default: $.noop
  31. A function that takes a date as a parameter and returns one of the following values:
  32. * undefined to have no effect
  33. * A Boolean, indicating whether or not this month is selectable
  34. * A String representing additional CSS classes to apply to the month's cell
  35. * An object with the following properties:
  36. * ``enabled``: same as the Boolean value above
  37. * ``classes``: same as the String value above
  38. * ``tooltip``: a tooltip to apply to this date, via the ``title`` HTML attribute
  39. beforeShowYear
  40. --------------
  41. Function(Date). Default: $.noop
  42. A function that takes a date as a parameter and returns one of the following values:
  43. * undefined to have no effect
  44. * A Boolean, indicating whether or not this year is selectable
  45. * A String representing additional CSS classes to apply to the year's cell
  46. * An object with the following properties:
  47. * ``enabled``: same as the Boolean value above
  48. * ``classes``: same as the String value above
  49. * ``tooltip``: a tooltip to apply to this year, via the ``title`` HTML attribute
  50. beforeShowDecade
  51. ----------------
  52. Function(Date). Default: $.noop
  53. A function that takes a date as a parameter and returns one of the following values:
  54. * undefined to have no effect
  55. * A Boolean, indicating whether or not this year is selectable
  56. * A String representing additional CSS classes to apply to the year's cell
  57. * An object with the following properties:
  58. * ``enabled``: same as the Boolean value above
  59. * ``classes``: same as the String value above
  60. * ``tooltip``: a tooltip to apply to this year, via the ``title`` HTML attribute
  61. beforeShowCentury
  62. -----------------
  63. Function(Date). Default: $.noop
  64. A function that takes a date as a parameter and returns one of the following values:
  65. * undefined to have no effect
  66. * A Boolean, indicating whether or not this year is selectable
  67. * A String representing additional CSS classes to apply to the year's cell
  68. * An object with the following properties:
  69. * ``enabled``: same as the Boolean value above
  70. * ``classes``: same as the String value above
  71. * ``tooltip``: a tooltip to apply to this year, via the ``title`` HTML attribute
  72. calendarWeeks
  73. -------------
  74. Boolean. Default: false
  75. Whether or not to show week numbers to the left of week rows.
  76. .. figure:: _static/screenshots/option_calendarweeks.png
  77. :align: center
  78. clearBtn
  79. --------
  80. Boolean. Default: false
  81. If true, displays a "Clear" button at the bottom of the datepicker to clear the input value. If "autoclose" is also set to true, this button will also close the datepicker.
  82. .. figure:: _static/screenshots/option_clearbtn.png
  83. :align: center
  84. container
  85. ---------
  86. String. Default: "body"
  87. Appends the date picker popup to a specific element; eg: container: '#picker-container' (will default to "body")
  88. .. _datesDisabled:
  89. datesDisabled
  90. -------------
  91. String, Array. Default: []
  92. Array of date strings or a single date string formatted in the given date format
  93. .. _daysOfWeekDisabled:
  94. daysOfWeekDisabled
  95. ------------------
  96. String, Array. Default: []
  97. Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: ``'06'`` or ``'0,6'`` or ``[0,6]``.
  98. .. figure:: _static/screenshots/option_daysofweekdisabled.png
  99. :align: center
  100. .. _daysOfWeekHighlighted:
  101. daysOfWeekHighlighted
  102. ---------------------
  103. String, Array. Default: []
  104. Days of the week that should be highlighted. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: highlight weekends: ``'06'`` or ``'0,6'`` or ``[0,6]``.
  105. defaultViewDate
  106. ---------------
  107. Date, String or Object with keys ``year``, ``month``, and ``day``. Default: today
  108. Date to view when initially opening the calendar. The internal value of the date remains today as default, but when the datepicker is first opened the calendar will open to ``defaultViewDate`` rather than today. If this option is not used, "today" remains the default view date.
  109. This option can be:
  110. * A date, which should be in local timezone.
  111. * A string which must be parsable with ``format``.
  112. * An object with keys ``year``, ``month`` and ``day`` (can't be set from a data attribute). If the given object is missing any of the required keys, their defaults are:
  113. * ``year``: the current year
  114. * ``month``: 0 (Note that it starts with 0 for January)
  115. * ``day``: 1
  116. disableTouchKeyboard
  117. --------------------
  118. Boolean. Default: false
  119. If true, no keyboard will show on mobile devices
  120. enableOnReadonly
  121. ----------------
  122. Boolean. Default: true
  123. If false the datepicker will not show on a readonly datepicker field.
  124. .. _endDate:
  125. endDate
  126. -------
  127. Date or String. Default: End of time
  128. The latest date that may be selected; all later dates will be disabled.
  129. Date should be in local timezone. String must be parsable with ``format``.
  130. .. figure:: _static/screenshots/option_enddate.png
  131. :align: center
  132. .. code-block:: html
  133. <input type="text" class="form-control" data-date-end-date="0d">
  134. Will disable all dates after today.
  135. forceParse
  136. ----------
  137. Boolean. Default: true
  138. Whether or not to force parsing of the input value when the picker is closed. That is, when an invalid date is left in the input field by the user, the picker will forcibly parse that value, and set the input's value to the new, valid date, conforming to the given `format`.
  139. format
  140. ------
  141. String. Default: "mm/dd/yyyy"
  142. The date format, combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy.
  143. * d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05.
  144. * D, DD: Abbreviated and full weekday names, respectively. Eg, Mon, Monday.
  145. * m, mm: Numeric month, no leading zero and leading zero, respectively. Eg, 7, 07.
  146. * M, MM: Abbreviated and full month names, respectively. Eg, Jan, January
  147. * yy, yyyy: 2- and 4-digit years, respectively. Eg, 12, 2012.
  148. Object.
  149. Custom formatting options
  150. * toDisplay: function (date, format, language) to convert date object to string, that will be stored in input field
  151. * toValue: function (date, format, language) to convert string object to date, that will be used in date selection
  152. ::
  153. $('.datepicker').datepicker({
  154. format: {
  155. /*
  156. * Say our UI should display a week ahead,
  157. * but textbox should store the actual date.
  158. * This is useful if we need UI to select local dates,
  159. * but store in UTC
  160. */
  161. toDisplay: function (date, format, language) {
  162. var d = new Date(date);
  163. d.setDate(d.getDate() - 7);
  164. return d.toISOString();
  165. },
  166. toValue: function (date, format, language) {
  167. var d = new Date(date);
  168. d.setDate(d.getDate() + 7);
  169. return new Date(d);
  170. }
  171. }
  172. });
  173. immediateUpdates
  174. ----------------
  175. Boolean. Default: false
  176. If true, selecting a year or month in the datepicker will update the input value immediately. Otherwise, only selecting a day of the month will update the input value immediately.
  177. inputs
  178. ------
  179. Array, jQuery. Default: None
  180. A list of inputs to be used in a range picker, which will be attached to the selected element. Allows for explicitly creating a range picker on a non-standard element.
  181. .. code-block:: html
  182. <div id="event_period">
  183. <input type="text" class="actual_range">
  184. <input type="text" class="actual_range">
  185. </div>
  186. ::
  187. $('#event_period').datepicker({
  188. inputs: $('.actual_range')
  189. });
  190. keepEmptyValues
  191. ---------------
  192. Boolean. Default: false
  193. Only effective in a range picker. If true, the selected value does not get propagated to other, currently empty, pickers in the range.
  194. keyboardNavigation
  195. ------------------
  196. Boolean. Default: true
  197. Whether or not to allow date navigation by arrow keys.
  198. Keyboard navigation is not supported at all for embedded / inline mode. Also it's not working if input element hasn't focus. This could be an issue if used as component or if opened by `show` method.
  199. language
  200. --------
  201. String. Default: "en"
  202. The IETF code (eg "en" for English, "pt-BR" for Brazilian Portuguese) of the language to use for month and day names. These will also be used as the input's value (and subsequently sent to the server in the case of form submissions). If a full code (eg "de-DE") is supplied the picker will first check for an "de-DE" language and if not found will fallback and check for a "de" language. If an unknown language code is given, English will be used. See :doc:`i18n`.
  203. .. figure:: _static/screenshots/option_language.png
  204. :align: center
  205. maxViewMode
  206. -----------
  207. Number, String. Default: 4, "centuries"
  208. Set a maximum limit for the view mode. Accepts: 0 or "days" or "month", 1 or "months" or "year", 2 or "years" or "decade", 3 or "decades" or "century", and 4 or "centuries" or "millenium".
  209. Gives the ability to pick only a day, a month, a year or a decade. The day is set to the 1st for "months", the month is set to January for "years", the year is set to the first year from the decade for "decades", and the year is set to the first from the millennium for "centuries".
  210. minViewMode
  211. -----------
  212. Number, String. Default: 0, "days"
  213. Set a minimum limit for the view mode. Accepts: 0 or "days" or "month", 1 or "months" or "year", 2 or "years" or "decade", 3 or "decades" or "century", and 4 or "centuries" or "millenium".
  214. Gives the ability to pick only a month, a year or a decade. The day is set to the 1st for "months", and the month is set to January for "years", the year is set to the first year from the decade for "decades", and the year is set to the first from the millennium for "centuries".
  215. multidate
  216. ---------
  217. Boolean, Number. Default: false
  218. Enable multidate picking. Each date in month view acts as a toggle button, keeping track of which dates the user has selected in order. If a number is given, the picker will limit how many dates can be selected to that number, dropping the oldest dates from the list when the number is exceeded. ``true`` equates to no limit. The input's value (if present) is set to a string generated by joining the dates, formatted, with ``multidateSeparator``.
  219. For selecting 2 dates as a range please see :ref:`daterange`
  220. .. figure:: _static/screenshots/option_multidate.png
  221. :align: center
  222. multidateSeparator
  223. ------------------
  224. String. Default: ","
  225. The string that will appear between dates when generating the input's value. When parsing the input's value for a multidate picker, this will also be used to split the incoming string to separate multiple formatted dates; as such, it is highly recommended that you not use a string that could be a substring of a formatted date (eg, using '-' to separate dates when your format is 'yyyy-mm-dd').
  226. orientation
  227. -----------
  228. String. Default: "auto"
  229. A space-separated string consisting of one or two of "left" or "right", "top" or "bottom", and "auto" (may be omitted); for example, "top left", "bottom" (horizontal orientation will default to "auto"), "right" (vertical orientation will default to "auto"), "auto top". Allows for fixed placement of the picker popup.
  230. "orientation" refers to the location of the picker popup's "anchor"; you can also think of it as the location of the trigger element (input, component, etc) relative to the picker.
  231. "auto" triggers "smart orientation" of the picker. Horizontal orientation will default to "left" and left offset will be tweaked to keep the picker inside the browser viewport; vertical orientation will simply choose "top" or "bottom", whichever will show more of the picker in the viewport.
  232. showOnFocus
  233. -----------
  234. Boolean. Default: true
  235. If false, the datepicker will be prevented from showing when the input field associated with it receives focus.
  236. .. _startdate:
  237. startDate
  238. ---------
  239. Date or String. Default: Beginning of time
  240. The earliest date that may be selected; all earlier dates will be disabled.
  241. Date should be in local timezone. String must be parsable with ``format``.
  242. .. figure:: _static/screenshots/option_startdate.png
  243. :align: center
  244. startView
  245. ---------
  246. Number, String. Default: 0, "days"
  247. The view that the datepicker should show when it is opened. Accepts: 0 or "days" or "month", 1 or "months" or "year", 2 or "years" or "decade", 3 or "decades" or "century", and 4 or "centuries" or "millenium". Useful for date-of-birth datepickers.
  248. templates
  249. ---------
  250. Object. Default:
  251. ::
  252. {
  253. leftArrow: '&laquo;',
  254. rightArrow: '&raquo;'
  255. }
  256. The templates used to generate some parts of the picker. Each property must be a string with only text, or valid html.
  257. You can use this property to use custom icons libs. for example:
  258. ::
  259. {
  260. leftArrow: '<i class="fa fa-long-arrow-left"></i>',
  261. rightArrow: '<i class="fa fa-long-arrow-right"></i>'
  262. }
  263. showWeekDays
  264. ------------
  265. Boolean. Default: true
  266. If false, the datepicker will not append the names of the weekdays to its view. Default behavior is appending the weekdays.
  267. title
  268. -----
  269. String. Default: ""
  270. The string that will appear on top of the datepicker. If empty the title will be hidden.
  271. todayBtn
  272. --------
  273. Boolean, "linked". Default: false
  274. If true or "linked", displays a "Today" button at the bottom of the datepicker to select the current date. If true, the "Today" button will only move the current date into view; if "linked", the current date will also be selected.
  275. .. figure:: _static/screenshots/option_todaybtn.png
  276. :align: center
  277. todayHighlight
  278. --------------
  279. Boolean. Default: false
  280. If true, highlights the current date.
  281. .. figure:: _static/screenshots/option_todayhighlight.png
  282. :align: center
  283. toggleActive
  284. ------------
  285. Boolean. Default: false
  286. If true, selecting the currently active date in the datepicker will unset the respective date. This option is always true when the multidate option is being used.
  287. updateViewDate
  288. --------------
  289. Boolean. Default: true
  290. If false viewDate is set according to `value` on initialization and updated
  291. * if a day in last oder next month is selected or
  292. * if dates are changed by `setDate`, `setDates`, `setUTCDate` and `setUTCDates` methods.
  293. If `multidate` option is `true` the last selected date or the last date in array
  294. passed to `setDates` or `setUTCDates` is used.
  295. weekStart
  296. ---------
  297. Integer. Default: 0
  298. Day of the week start. 0 (Sunday) to 6 (Saturday)
  299. .. figure:: _static/screenshots/option_weekstart.png
  300. :align: center
  301. zIndexOffset
  302. ------------
  303. Integer. Default: 10
  304. The CSS z-index of the open datepicker is the maximum z-index of the input and all of its DOM ancestors *plus* the ``zIndexOffset``.
  305. Quick reference
  306. ===============
  307. This is a quick overview of all the options and their default values
  308. ===================== =============
  309. Option Default value
  310. ===================== =============
  311. autoclose false
  312. assumeNearbyYear false
  313. beforeShowDay
  314. beforeShowMonth
  315. beforeShowYear
  316. beforeShowDecade
  317. beforeShowCentury
  318. calendarWeeks false
  319. clearBtn false
  320. container 'body'
  321. datesDisabled []
  322. daysOfWeekDisabled []
  323. daysOfWeekHighlighted []
  324. defaultViewDate today
  325. disableTouchKeyboard false
  326. enableOnReadonly true
  327. endDate Infinity
  328. forceParse true
  329. format 'mm/dd/yyyy'
  330. immediateUpdates false
  331. inputs
  332. keepEmptyValues false
  333. keyboardNavigation true
  334. language 'en'
  335. maxViewMode 4 'centuries'
  336. minViewMode 0 'days'
  337. multidate false
  338. multidateSeparator ','
  339. orientation 'auto'
  340. showOnFocus true
  341. startDate -Infinity
  342. startView 0 'days' (current month)
  343. templates
  344. title ''
  345. todayBtn false
  346. todayHighlight true
  347. toggleActive false
  348. weekStart 0 (Sunday)
  349. zIndexOffset 10
  350. ===================== =============