@wernfried/daterangepicker 4.17.0 → 4.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API_Doc.md +662 -8
- package/README.md +138 -5
- package/dist/esm/daterangepicker.js +128 -118
- package/dist/esm/daterangepicker.min.js +2 -2
- package/dist/global/daterangepicker.js +128 -118
- package/dist/global/daterangepicker.min.js +2 -2
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ Above samples are based on the [original repository](https://github.com/dangross
|
|
|
20
20
|
```html
|
|
21
21
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
|
|
22
22
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script>
|
|
23
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.
|
|
24
|
-
<link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.
|
|
23
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.2/dist/global/daterangepicker.min.js"></script>
|
|
24
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.2/css/daterangepicker.min.css" rel="stylesheet" />
|
|
25
25
|
|
|
26
26
|
<input type="text" id="picker" />
|
|
27
27
|
|
|
@@ -43,11 +43,11 @@ Above samples are based on the [original repository](https://github.com/dangross
|
|
|
43
43
|
"imports": {
|
|
44
44
|
"jquery": "https://cdn.jsdelivr.net/npm/jquery@4.0.0/+esm",
|
|
45
45
|
"luxon": "https://cdn.jsdelivr.net/npm/luxon@3.7.2/+esm",
|
|
46
|
-
"daterangepicker": "https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.
|
|
46
|
+
"daterangepicker": "https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.2/+esm"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
</script>
|
|
50
|
-
<link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.
|
|
50
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.2/css/daterangepicker.min.css" rel="stylesheet" />
|
|
51
51
|
|
|
52
52
|
<input type="text" id="picker" />
|
|
53
53
|
|
|
@@ -68,7 +68,7 @@ Above samples are based on the [original repository](https://github.com/dangross
|
|
|
68
68
|
```html
|
|
69
69
|
<script ...></script>
|
|
70
70
|
<link type="text/css" href="https://cdn.jsdelivr.net/npm/bulma@1.0.4/css/bulma.min.css" rel="stylesheet" />
|
|
71
|
-
<link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.
|
|
71
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/@wernfried/daterangepicker@4.17.2/css/daterangepicker.bulma.min.css" rel="stylesheet" />
|
|
72
72
|
|
|
73
73
|
<input type="text" id="picker" />
|
|
74
74
|
|
|
@@ -257,3 +257,136 @@ Licensed under the [MIT license](LICENSE).
|
|
|
257
257
|
|
|
258
258
|
## API Documentation
|
|
259
259
|
[API Documentation](API_Doc.md)
|
|
260
|
+
## Options
|
|
261
|
+
Options for DateRangePicker
|
|
262
|
+
|
|
263
|
+
**Kind**: global typedef
|
|
264
|
+
**Properties**
|
|
265
|
+
|
|
266
|
+
| Name | Type | Default | Description |
|
|
267
|
+
| --- | --- | --- | --- |
|
|
268
|
+
| parentEl | <code>string</code> | <code>"body"</code> | [jQuery selector](https://api.jquery.com/category/selectors/) of the parent element that the date range picker will be added to |
|
|
269
|
+
| startDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> \| <code>null</code> | | Default: `DateTime.now().startOf('day')`<br>The beginning date of the initially selected date range.<br> Must be a `luxon.DateTime` or `Date` or `string` according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) or a string matching `locale.format`.<br> Date value is rounded to match option `timePickerStepSize`<br> Option `isInvalidDate` and `isInvalidTime` are not evaluated, you may set date/time which is not selectable in calendar.<br> If the date does not fall into `minDate` and `maxDate` then date is shifted and a warning is written to console.<br> Use `startDate: null` to show calendar without an inital selected date. |
|
|
270
|
+
| endDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> | | Defautl: `DateTime.now().endOf('day')`<br>The end date of the initially selected date range.<br> Must be a `luxon.DateTime` or `Date` or `string` according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) or a string matching `locale.format`.<br> Date value is rounded to match option `timePickerStepSize`<br> Option `isInvalidDate`, `isInvalidTime` and `minSpan`, `maxSpan` are not evaluated, you may set date/time which is not selectable in calendar.<br> If the date does not fall into `minDate` and `maxDate` then date is shifted and a warning is written to console.<br> |
|
|
271
|
+
| minDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> \| <code>null</code> | | The earliest date a user may select or `null` for no limit.<br> Must be a `luxon.DateTime` or `Date` or `string` according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) or a string matching `locale.format`. |
|
|
272
|
+
| maxDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> \| <code>null</code> | | The latest date a user may select or `null` for no limit.<br> Must be a `luxon.DateTime` or `Date` or `string` according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) or a string matching `locale.format`. |
|
|
273
|
+
| minSpan | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> \| <code>null</code> | | The minimum span between the selected start and end dates.<br> Must be a `luxon.Duration` or number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Ignored when `singleDatePicker: true` |
|
|
274
|
+
| maxSpan | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> \| <code>null</code> | | The maximum span between the selected start and end dates.<br> Must be a `luxon.Duration` or number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Ignored when `singleDatePicker: true` |
|
|
275
|
+
| defaultSpan | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> \| <code>null</code> | | The span which is used when endDate is automatically updated due to wrong user input<br> Must be a `luxon.Duration` or number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Ignored when `singleDatePicker: true`. Not relevant if `minSpan: null` |
|
|
276
|
+
| initalMonth | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> \| <code>null</code> | | Default: `DateTime.now().startOf('month')`<br> The inital month shown when `startDate: null`. Be aware, the attached `<input>` element must be also empty.<br> Must be a `luxon.DateTime` or `Date` or `string` according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) or a string matching `locale.format`.<br> When `initalMonth` is used, then `endDate` is ignored and it works only with `timePicker: false` |
|
|
277
|
+
| autoApply | <code>boolean</code> | <code>false</code> | Hide the `Apply` and `Cancel` buttons, and automatically apply a new date range as soon as two dates are clicked.<br> Only useful when `timePicker: false` |
|
|
278
|
+
| singleDatePicker | <code>boolean</code> | <code>false</code> | Show only a single calendar to choose one date, instead of a range picker with two calendars.<br> If `true`, then `endDate` is always `null`. |
|
|
279
|
+
| singleMonthView | <code>boolean</code> | <code>false</code> | Show only a single month calendar, useful when selected ranges are usually short<br> or for smaller viewports like mobile devices.<br> Ignored for `singleDatePicker: true`. |
|
|
280
|
+
| showDropdowns | <code>boolean</code> | <code>false</code> | Show year and month select boxes above calendars to jump to a specific month and year |
|
|
281
|
+
| minYear | <code>number</code> | | Default: `DateTime.now().minus({year:100}).year`<br>The minimum year shown in the dropdowns when `showDropdowns: true` |
|
|
282
|
+
| maxYear | <code>number</code> | | Default: `DateTime.now().plus({year:100}).year`<br>The maximum year shown in the dropdowns when `showDropdowns: true` |
|
|
283
|
+
| showWeekNumbers | <code>boolean</code> | <code>false</code> | Show **localized** week numbers at the start of each week on the calendars |
|
|
284
|
+
| showISOWeekNumbers | <code>boolean</code> | <code>false</code> | Show **ISO** week numbers at the start of each week on the calendars.<br> Takes precedence over localized `showWeekNumbers` |
|
|
285
|
+
| timePicker | <code>boolean</code> | <code>false</code> | Adds select boxes to choose times in addition to dates |
|
|
286
|
+
| timePicker24Hour | <code>boolean</code> | <code>true|false</code> | Use 24-hour instead of 12-hour times, removing the AM/PM selection.<br> Default is derived from current locale [Intl.DateTimeFormat.resolvedOptions.hour12](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#hour12). |
|
|
287
|
+
| timePickerStepSize | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> | | Default: `Duration.fromObject({minutes:1})`<br>Set the time picker step size.<br> Must be a `luxon.Duration` or the number of seconds or a string according to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) duration.<br> Valid values are 1,2,3,4,5,6,10,12,15,20,30 for `Duration.fromObject({seconds: ...})` and `Duration.fromObject({minutes: ...})` and 1,2,3,4,6,(8,12) for `Duration.fromObject({hours: ...})`.<br> Duration must be greater than `minSpan` and smaller than `maxSpan`.<br> For example `timePickerStepSize: 600` will disable time picker seconds and time picker minutes are set to step size of 10 Minutes.<br> Overwrites `timePickerIncrement` and `timePickerSeconds`, ignored when `timePicker: false` |
|
|
288
|
+
| timePickerSeconds | <code>boolean</code> | <code>boolean</code> | **Deprecated**, use `timePickerStepSize`<br>Show seconds in the timePicker |
|
|
289
|
+
| timePickerIncrement | <code>boolean</code> | <code>1</code> | **Deprecated**, use `timePickerStepSize`<br>Increment of the minutes selection list for times |
|
|
290
|
+
| autoUpdateInput | <code>boolean</code> | <code>true</code> | Indicates whether the date range picker should instantly update the value of the attached `<input>` element when the selected dates change.<br>The `<input>` element will be always updated on `Apply` and reverted when user clicks on `Cancel`. |
|
|
291
|
+
| onOutsideClick | <code>string</code> | <code>"apply"</code> | Defines what picker shall do when user clicks outside the calendar. `'apply'` or `'cancel'`. Event [onOutsideClick.daterangepicker](#event_outsideClick.daterangepicker) is always emitted. |
|
|
292
|
+
| linkedCalendars | <code>boolean</code> | <code>true</code> | When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars.<br> When disabled, the two calendars can be individually advanced and display any month/year |
|
|
293
|
+
| isInvalidDate | <code>function</code> | <code>false</code> | A function that is passed each date in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidDate(date)`<br> |
|
|
294
|
+
| isInvalidTime | <code>function</code> | <code>false</code> | A function that is passed each hour/minute/second/am-pm in the two calendars before they are displayed,<br> and may return `true` or `false` to indicate whether that date should be available for selection or not.<br> Signature: `isInvalidTime(time, side, unit)`<br> `side` is `'start'` or `'end'` or `null` for `singleDatePicker: true`<br> `unit` is `'hour'`, `'minute'`, `'second'` or `'ampm'`<br> Hours are always given as 24-hour clock<br> Ensure that your function returns `false` for at least one item. Otherwise the calender is not rendered.<br> |
|
|
295
|
+
| isCustomDate | <code>function</code> | <code>false</code> | A function that is passed each date in the two calendars before they are displayed, and may return a string or array of CSS class names to apply to that date's calendar cell.<br> Signature: `isCustomDate(date)` |
|
|
296
|
+
| altInput | <code>string</code> \| <code>Array</code> | <code>null</code> | A [jQuery selector](https://api.jquery.com/category/selectors/) string for an alternative output (typically hidden) `<input>` element. Uses `altFormat` to format the value.<br> Must be a single string for `singleDatePicker: true` or an array of two strings for `singleDatePicker: false`<br> Example: `['#start', '#end']` |
|
|
297
|
+
| altFormat | <code>function</code> \| <code>string</code> | | The output format used for `altInput`.<br> Default: ISO-8601 basic format without time zone, precisison is derived from `timePicker` and `timePickerStepSize`<br> Example `yyyyMMdd'T'HHmm` for `timePicker=true` and display of Minutes<br> If defined, either a string used with [Format tokens](https://moment.github.io/luxon/#/formatting?id=table-of-tokens) or a function.<br> Examples: `"yyyy:MM:dd'T'HH:mm"`,<br>`(date) => date.toUnixInteger()` |
|
|
298
|
+
| ~~warnings~~ | <code>boolean</code> | | Not used anymore. Listen to event `violated.daterangepicker` to react on invalid input data |
|
|
299
|
+
| applyButtonClasses | <code>string</code> | <code>"btn-primary"</code> | CSS class names that will be added only to the apply button |
|
|
300
|
+
| cancelButtonClasses | <code>string</code> | <code>"btn-default"</code> | CSS class names that will be added only to the cancel button |
|
|
301
|
+
| buttonClasses | <code>string</code> | | Default: `'btn btn-sm'`<br>CSS class names that will be added to both the apply and cancel buttons. |
|
|
302
|
+
| weekendClasses | <code>string</code> | <code>"weekend"</code> | CSS class names that will be used to highlight weekend days.<br> Use `null` or empty string if you don't like to highlight weekend days. |
|
|
303
|
+
| weekendDayClasses | <code>string</code> | <code>"weekend-day"</code> | CSS class names that will be used to highlight weekend day names.<br> Weekend days are evaluated by [Info.getWeekendWeekdays](https://moment.github.io/luxon/api-docs/index.html#infogetweekendweekdays) and depend on current locale settings. Use `null` or empty string if you don't like to highlight weekend day names. |
|
|
304
|
+
| todayClasses | <code>string</code> | <code>"today"</code> | CSS class names that will be used to highlight the current day.<br> Use `null` or empty string if you don't like to highlight the current day. |
|
|
305
|
+
| externalStyle | <code>string</code> | <code>null</code> | External CSS Framework to style the picker. Currently only `'bulma'` is supported. |
|
|
306
|
+
| opens | <code>string</code> | <code>"right"</code> | Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to.<br> `'left' \| 'right' \| 'center'` |
|
|
307
|
+
| drops | <code>string</code> | <code>"down"</code> | Whether the picker appears below or above the HTML element it's attached to.<br> `'down' \| 'up' \| 'auto'` |
|
|
308
|
+
| ranges | <code>object</code> | <code>{}</code> | Set predefined date [Ranges](#Ranges) the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range. |
|
|
309
|
+
| showCustomRangeLabel | <code>boolean</code> | <code>true</code> | Displays "Custom Range" at the end of the list of predefined [Ranges](#Ranges), when the ranges option is used.<br> This option will be highlighted whenever the current date range selection does not match one of the predefined ranges.<br> Clicking it will display the calendars to select a new range. |
|
|
310
|
+
| alwaysShowCalendars | <code>boolean</code> | <code>false</code> | Normally, if you use the ranges option to specify pre-defined date ranges, calendars for choosing a custom date range are not shown until the user clicks "Custom Range".<br> When this option is set to true, the calendars for choosing a custom date range are always shown instead. |
|
|
311
|
+
| showLabel= | <code>boolean</code> | | Shows selected range next to Apply buttons.<br> Defaults to `false` if anchor element is `<input type="text">`, otherwise `true` |
|
|
312
|
+
| locale | <code>object</code> | <code>{}</code> | Allows you to provide localized strings for buttons and labels, customize the date format, and change the first day of week for the calendars. |
|
|
313
|
+
| locale.direction | <code>string</code> | <code>"ltr"</code> | Direction of reading, `'ltr'` or `'rtl'` |
|
|
314
|
+
| locale.format | <code>object</code> \| <code>string</code> | | Default: `DateTime.DATE_SHORT` or `DateTime.DATETIME_SHORT` when `timePicker: true`<br>Date formats. Either given as string, see [Format Tokens](https://moment.github.io/luxon/#/formatting?id=table-of-tokens) or an object according to [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat)<br> I recommend to use the luxon [Presets](https://moment.github.io/luxon/#/formatting?id=presets). |
|
|
315
|
+
| locale.separator | <code>string</code> | | Defaut: `' - '`<br>Separator for start and end time |
|
|
316
|
+
| locale.weekLabel | <code>string</code> | <code>"W"</code> | Label for week numbers |
|
|
317
|
+
| locale.daysOfWeek | <code>Array</code> | | Default: `luxon.Info.weekdays('short')`<br>Array with weekday names, from Monday to Sunday |
|
|
318
|
+
| locale.monthNames | <code>Array</code> | | Default: `luxon.Info.months('long')`<br>Array with month names |
|
|
319
|
+
| locale.firstDay | <code>number</code> | | Default: `luxon.Info.getStartOfWeek()`<br>First day of the week, 1 for Monday through 7 for Sunday |
|
|
320
|
+
| locale.applyLabel | <code>string</code> | <code>"Apply"</code> | Label of `Apply` Button |
|
|
321
|
+
| locale.cancelLabel | <code>string</code> | <code>"Cancel"</code> | Label of `Cancel` Button |
|
|
322
|
+
| locale.customRangeLabel | <code>string</code> | <code>"Custom"</code> | Range - Title for custom ranges |
|
|
323
|
+
| locale.durationFormat | <code>object</code> \| <code>string</code> \| <code>function</code> | <code>{}</code> | Format a custom label for selected duration, for example `'5 Days, 12 Hours'`.<br> Define the format either as string, see [Duration.toFormat - Format Tokens](https://moment.github.io/luxon/api-docs/index.html#durationtoformat) or an object according to [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options), see [Duration.toHuamn](https://moment.github.io/luxon/api-docs/index.html#durationtohuman).<br> Or custom function as `(startDate, endDate) => {}` |
|
|
324
|
+
|
|
325
|
+
<a name="Ranges"></a>
|
|
326
|
+
|
|
327
|
+
## Ranges : <code>Object</code>
|
|
328
|
+
A set of predefined ranges.<br>
|
|
329
|
+
Ranges are not validated against `minDate`, `maxDate`, `minSpan`, `maxSpan` or `timePickerStepSize ` constraints.
|
|
330
|
+
|
|
331
|
+
**Kind**: global typedef
|
|
332
|
+
**Properties**
|
|
333
|
+
|
|
334
|
+
| Name | Type | Description |
|
|
335
|
+
| --- | --- | --- |
|
|
336
|
+
| name | <code>string</code> | The name of the range |
|
|
337
|
+
| range | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> | Array of 2 elements with `startDate` and `endDate` |
|
|
338
|
+
|
|
339
|
+
**Example**
|
|
340
|
+
```js
|
|
341
|
+
{
|
|
342
|
+
'Today': [DateTime.now().startOf('day'), DateTime.now().endOf('day')],
|
|
343
|
+
'Yesterday': [DateTime.now().startOf('day').minus({days: 1}), DateTime.now().minus({days: 1}).endOf('day')],
|
|
344
|
+
'Last 7 Days': [DateTime.now().startOf('day').minus({days: 6}), DateTime.now()],
|
|
345
|
+
'Last 30 Days': [DateTime.now().startOf('day').minus({days: 29}), DateTime.now()],
|
|
346
|
+
'This Month': [DateTime.now().startOf('day').startOf('month'), DateTime.now().endOf('month')],
|
|
347
|
+
'Last Month': [DateTime.now().startOf('day').minus({months: 1}).startOf('month'), DateTime.now().minus({months: 1}).endOf('month')]
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
<a name="Range"></a>
|
|
351
|
+
|
|
352
|
+
## Range : <code>Object</code>
|
|
353
|
+
A single predefined range
|
|
354
|
+
|
|
355
|
+
**Kind**: global typedef
|
|
356
|
+
**Properties**
|
|
357
|
+
|
|
358
|
+
| Name | Type | Description |
|
|
359
|
+
| --- | --- | --- |
|
|
360
|
+
| name | <code>string</code> | The name of the range |
|
|
361
|
+
| range | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| [<code>Date</code>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) \| <code>string</code> | Array of 2 elements with startDate and endDate |
|
|
362
|
+
|
|
363
|
+
**Example**
|
|
364
|
+
```js
|
|
365
|
+
{ Today: [DateTime.now().startOf('day'), DateTime.now().endOf('day')] }
|
|
366
|
+
```
|
|
367
|
+
<a name="InputViolation"></a>
|
|
368
|
+
|
|
369
|
+
## InputViolation : <code>Object</code>
|
|
370
|
+
**Kind**: global typedef
|
|
371
|
+
**Properties**
|
|
372
|
+
|
|
373
|
+
| Name | Type | Description |
|
|
374
|
+
| --- | --- | --- |
|
|
375
|
+
| startDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) | Violation of startDate |
|
|
376
|
+
| endDate? | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) \| <code>undefined</code> | Violation of endDate, if existing |
|
|
377
|
+
| violations | <code>Array</code> | The constraints which violates the input |
|
|
378
|
+
| reason | <code>Array</code> | The type/reson of violation |
|
|
379
|
+
| old | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) | Old value startDate/endDate |
|
|
380
|
+
| new? | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) | Corrected value of startDate/endDate if existing |
|
|
381
|
+
|
|
382
|
+
<a name="callback"></a>
|
|
383
|
+
|
|
384
|
+
## callback : <code>function</code>
|
|
385
|
+
**Kind**: global typedef
|
|
386
|
+
|
|
387
|
+
| Param | Type | Description |
|
|
388
|
+
| --- | --- | --- |
|
|
389
|
+
| startDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) | Selected startDate |
|
|
390
|
+
| endDate | [<code>DateTime</code>](https://moment.github.io/luxon/api-docs/index.html#datetime) | Selected endDate |
|
|
391
|
+
| range | <code>string</code> | |
|
|
392
|
+
|
|
@@ -336,29 +336,16 @@ class DateRangePicker {
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
if (!this.timePicker) {
|
|
340
|
-
if (this.minDate)
|
|
341
|
-
this.minDate = this.minDate.startOf("day");
|
|
342
|
-
if (this.maxDate)
|
|
343
|
-
this.maxDate = this.maxDate.endOf("day");
|
|
344
|
-
}
|
|
345
339
|
if (this.singleDatePicker) {
|
|
346
340
|
this.#endDate = this.#startDate;
|
|
347
341
|
} else if (this.#endDate < this.#startDate) {
|
|
348
342
|
console.error(`Option 'endDate' ${this.#endDate} must not be earlier than 'startDate' ${this.#startDate}`);
|
|
349
343
|
}
|
|
350
|
-
if (
|
|
351
|
-
this.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
} else if (!this.singleDatePicker && Array.isArray(options.altInput) && options.altInput.length === 2) {
|
|
356
|
-
this.altInput = options.altInput.every((x) => typeof x === "string" && $(x).is("input:text")) ? options.altInput : null;
|
|
357
|
-
} else {
|
|
358
|
-
const note = `Value of "altInput" must be ` + (this.singleDatePicker ? "a string" : "an array of two string elements");
|
|
359
|
-
console.error(`Option 'altInput' ${JSON.stringify(options.altInput)} is not valid
|
|
360
|
-
`, note);
|
|
361
|
-
}
|
|
344
|
+
if (!this.timePicker) {
|
|
345
|
+
if (this.minDate) this.minDate = this.minDate.startOf("day");
|
|
346
|
+
if (this.maxDate) this.maxDate = this.maxDate.endOf("day");
|
|
347
|
+
this.#startDate = this.#startDate.startOf("day");
|
|
348
|
+
this.#endDate = this.#endDate.endOf("day");
|
|
362
349
|
}
|
|
363
350
|
if (options.warnings !== void 0)
|
|
364
351
|
console.warn(`Option 'warnings' not used anymore. Listen to event 'violated.daterangepicker'`);
|
|
@@ -375,6 +362,8 @@ class DateRangePicker {
|
|
|
375
362
|
console.error(`Value of startDate "${this.#startDate}" violates ${vio.find((x) => x.reason.startsWith("isInvalid")).reason}`);
|
|
376
363
|
} else {
|
|
377
364
|
const newDate = vio.filter((x) => x.new != null).at(-1).new;
|
|
365
|
+
if (process.env.JEST_WORKER_ID == null)
|
|
366
|
+
console.warn(`Correcting startDate from ${this.#startDate} to ${newDate}`);
|
|
378
367
|
this.#startDate = newDate;
|
|
379
368
|
}
|
|
380
369
|
}
|
|
@@ -385,12 +374,27 @@ class DateRangePicker {
|
|
|
385
374
|
console.error(`Value of endDate "${this.#endDate}" violates ${vio.find((x) => x.reason.startsWith("isInvalid")).reason}`);
|
|
386
375
|
} else {
|
|
387
376
|
const newDate = vio.filter((x) => x.new != null).at(-1).new;
|
|
377
|
+
if (process.env.JEST_WORKER_ID == null)
|
|
378
|
+
console.warn(`Correcting endDate from ${this.#endDate} to ${newDate}`);
|
|
388
379
|
this.#endDate = newDate;
|
|
389
380
|
}
|
|
390
381
|
}
|
|
391
382
|
}
|
|
392
383
|
}
|
|
393
384
|
}
|
|
385
|
+
if (["function", "string"].includes(typeof options.altFormat))
|
|
386
|
+
this.altFormat = options.altFormat;
|
|
387
|
+
if (typeof options.altInput === "string" || Array.isArray(options.altInput)) {
|
|
388
|
+
if (this.singleDatePicker && typeof options.altInput === "string") {
|
|
389
|
+
this.altInput = $(options.altInput).is("input:text") ? options.altInput : null;
|
|
390
|
+
} else if (!this.singleDatePicker && Array.isArray(options.altInput) && options.altInput.length === 2) {
|
|
391
|
+
this.altInput = options.altInput.every((x) => typeof x === "string" && $(x).is("input:text")) ? options.altInput : null;
|
|
392
|
+
} else {
|
|
393
|
+
const note = `Value of "altInput" must be ` + (this.singleDatePicker ? "a string" : "an array of two string elements");
|
|
394
|
+
console.error(`Option 'altInput' ${JSON.stringify(options.altInput)} is not valid
|
|
395
|
+
`, note);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
394
398
|
if (typeof options.opens === "string") {
|
|
395
399
|
if (["left", "right", "center"].includes(options.opens))
|
|
396
400
|
this.opens = options.opens;
|
|
@@ -467,10 +471,6 @@ class DateRangePicker {
|
|
|
467
471
|
if (typeof cb === "function")
|
|
468
472
|
this.callback = cb;
|
|
469
473
|
if (!this.timePicker) {
|
|
470
|
-
if (this.#startDate)
|
|
471
|
-
this.#startDate = this.#startDate.startOf("day");
|
|
472
|
-
if (this.#endDate)
|
|
473
|
-
this.#endDate = this.#endDate.endOf("day");
|
|
474
474
|
this.container.find(".calendar-time").hide();
|
|
475
475
|
}
|
|
476
476
|
if (this.timePicker && this.autoApply)
|
|
@@ -532,6 +532,7 @@ class DateRangePicker {
|
|
|
532
532
|
set endDate(val) {
|
|
533
533
|
this.#endDate = val;
|
|
534
534
|
}
|
|
535
|
+
/* #region Set startDate/endDate */
|
|
535
536
|
/**
|
|
536
537
|
* Sets the date range picker's currently selected start date to the provided date.<br>
|
|
537
538
|
* `startDate` must be a `luxon.DateTime` or `Date` or `string` according to {@link ISO-8601} or a string matching `locale.format`.<br>
|
|
@@ -650,6 +651,7 @@ class DateRangePicker {
|
|
|
650
651
|
}
|
|
651
652
|
}
|
|
652
653
|
}
|
|
654
|
+
/* #endregion */
|
|
653
655
|
logDate(date) {
|
|
654
656
|
return this.timePicker ? date.toISO({ suppressMilliseconds: true }) : date.toISODate();
|
|
655
657
|
}
|
|
@@ -927,6 +929,7 @@ class DateRangePicker {
|
|
|
927
929
|
return result;
|
|
928
930
|
}
|
|
929
931
|
}
|
|
932
|
+
/* #region Rendering */
|
|
930
933
|
/**
|
|
931
934
|
* Updates the picker when calendar is initiated or any date has been selected.
|
|
932
935
|
* Could be useful after running {@link #DateRangePicker+setStartDate|setStartDate} or {@link #DateRangePicker+setEndDate|setRange}
|
|
@@ -1369,6 +1372,8 @@ class DateRangePicker {
|
|
|
1369
1372
|
this.container.find("button.applyBtn").prop("disabled", true);
|
|
1370
1373
|
}
|
|
1371
1374
|
}
|
|
1375
|
+
/* #endregion */
|
|
1376
|
+
/* #region Move/Show/Hide */
|
|
1372
1377
|
/**
|
|
1373
1378
|
* Place the picker at the right place in the document
|
|
1374
1379
|
* @private
|
|
@@ -1512,25 +1517,6 @@ class DateRangePicker {
|
|
|
1512
1517
|
}
|
|
1513
1518
|
}
|
|
1514
1519
|
/**
|
|
1515
|
-
* Closes the picker when user clicks outside
|
|
1516
|
-
* @param {external:jQuery} e - The Event target
|
|
1517
|
-
* @emits "outsideClick.daterangepicker"
|
|
1518
|
-
* @private
|
|
1519
|
-
*/
|
|
1520
|
-
outsideClick(e) {
|
|
1521
|
-
var target = $(e.target);
|
|
1522
|
-
if (
|
|
1523
|
-
// ie modal dialog fix
|
|
1524
|
-
e.type === "focusin" || target.closest(this.element).length || target.closest(this.container).length || target.closest(".calendar-table").length
|
|
1525
|
-
) return;
|
|
1526
|
-
if (this.onOutsideClick === "cancel") {
|
|
1527
|
-
this.#startDate = this.oldStartDate;
|
|
1528
|
-
this.#endDate = this.oldEndDate;
|
|
1529
|
-
}
|
|
1530
|
-
this.hide();
|
|
1531
|
-
this.element.trigger("outsideClick.daterangepicker", this);
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
1520
|
* Shows calendar when user selects "Custom Ranges"
|
|
1535
1521
|
* @emits "showCalendar.daterangepicker"
|
|
1536
1522
|
*/
|
|
@@ -1547,30 +1533,26 @@ class DateRangePicker {
|
|
|
1547
1533
|
this.container.removeClass("show-calendar");
|
|
1548
1534
|
this.element.trigger("hideCalendar.daterangepicker", this);
|
|
1549
1535
|
}
|
|
1536
|
+
/* #endregion */
|
|
1537
|
+
/* #region Handle mouse related events */
|
|
1550
1538
|
/**
|
|
1551
|
-
*
|
|
1539
|
+
* Closes the picker when user clicks outside
|
|
1552
1540
|
* @param {external:jQuery} e - The Event target
|
|
1541
|
+
* @emits "outsideClick.daterangepicker"
|
|
1553
1542
|
* @private
|
|
1554
1543
|
*/
|
|
1555
|
-
|
|
1556
|
-
var
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
this.
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
this.#startDate =
|
|
1563
|
-
this.#endDate =
|
|
1564
|
-
if (!this.timePicker) {
|
|
1565
|
-
this.#startDate.startOf("day");
|
|
1566
|
-
this.#endDate.endOf("day");
|
|
1567
|
-
}
|
|
1568
|
-
if (!this.alwaysShowCalendars)
|
|
1569
|
-
this.hideCalendars();
|
|
1570
|
-
if (this.element.triggerHandler("beforeHide.daterangepicker", this))
|
|
1571
|
-
this.updateView();
|
|
1572
|
-
this.clickApply();
|
|
1544
|
+
outsideClick(e) {
|
|
1545
|
+
var target = $(e.target);
|
|
1546
|
+
if (
|
|
1547
|
+
// ie modal dialog fix
|
|
1548
|
+
e.type === "focusin" || target.closest(this.element).length || target.closest(this.container).length || target.closest(".calendar-table").length
|
|
1549
|
+
) return;
|
|
1550
|
+
if (this.onOutsideClick === "cancel") {
|
|
1551
|
+
this.#startDate = this.oldStartDate;
|
|
1552
|
+
this.#endDate = this.oldEndDate;
|
|
1573
1553
|
}
|
|
1554
|
+
this.hide();
|
|
1555
|
+
this.element.trigger("outsideClick.daterangepicker", this);
|
|
1574
1556
|
}
|
|
1575
1557
|
/**
|
|
1576
1558
|
* Move calendar to previous month
|
|
@@ -1694,6 +1676,33 @@ class DateRangePicker {
|
|
|
1694
1676
|
$(el).removeClass("range-hover");
|
|
1695
1677
|
});
|
|
1696
1678
|
}
|
|
1679
|
+
/* #endregion */
|
|
1680
|
+
/* #region Select values by Mouse */
|
|
1681
|
+
/**
|
|
1682
|
+
* Set date values after user selected a date
|
|
1683
|
+
* @param {external:jQuery} e - The Event target
|
|
1684
|
+
* @private
|
|
1685
|
+
*/
|
|
1686
|
+
clickRange(e) {
|
|
1687
|
+
var label = e.target.getAttribute("data-range-key");
|
|
1688
|
+
this.chosenLabel = label;
|
|
1689
|
+
if (label == this.locale.customRangeLabel) {
|
|
1690
|
+
this.showCalendars();
|
|
1691
|
+
} else {
|
|
1692
|
+
var dates = this.ranges[label];
|
|
1693
|
+
this.#startDate = dates[0];
|
|
1694
|
+
this.#endDate = dates[1];
|
|
1695
|
+
if (!this.timePicker) {
|
|
1696
|
+
this.#startDate.startOf("day");
|
|
1697
|
+
this.#endDate.endOf("day");
|
|
1698
|
+
}
|
|
1699
|
+
if (!this.alwaysShowCalendars)
|
|
1700
|
+
this.hideCalendars();
|
|
1701
|
+
if (this.element.triggerHandler("beforeHide.daterangepicker", this))
|
|
1702
|
+
this.updateView();
|
|
1703
|
+
this.clickApply();
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1697
1706
|
/**
|
|
1698
1707
|
* User clicked a date
|
|
1699
1708
|
* @param {external:jQuery} e - The Event target
|
|
@@ -1808,64 +1817,6 @@ class DateRangePicker {
|
|
|
1808
1817
|
}
|
|
1809
1818
|
}
|
|
1810
1819
|
/**
|
|
1811
|
-
* User clicked `Apply` button
|
|
1812
|
-
* @emits "apply.daterangepicker"
|
|
1813
|
-
* @private
|
|
1814
|
-
*/
|
|
1815
|
-
clickApply() {
|
|
1816
|
-
this.hide();
|
|
1817
|
-
this.element.trigger("apply.daterangepicker", this);
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* User clicked `Cancel` button
|
|
1821
|
-
* @emits "cancel.daterangepicker"
|
|
1822
|
-
* @private
|
|
1823
|
-
*/
|
|
1824
|
-
clickCancel() {
|
|
1825
|
-
this.#startDate = this.oldStartDate;
|
|
1826
|
-
this.#endDate = this.oldEndDate;
|
|
1827
|
-
this.hide();
|
|
1828
|
-
this.element.trigger("cancel.daterangepicker", this);
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
* Calender month moved
|
|
1832
|
-
* @param {external:jQuery} e - The Event target
|
|
1833
|
-
* @private
|
|
1834
|
-
*/
|
|
1835
|
-
monthOrYearChanged(e) {
|
|
1836
|
-
var isLeft = $(e.target).closest(".drp-calendar").hasClass("left"), leftOrRight = isLeft ? "left" : "right", cal = this.container.find(".drp-calendar." + leftOrRight);
|
|
1837
|
-
var month = parseInt(cal.find(".monthselect").val(), 10);
|
|
1838
|
-
var year = cal.find(".yearselect").val();
|
|
1839
|
-
if (!isLeft) {
|
|
1840
|
-
if (year < this.#startDate.year || year == this.#startDate.year && month < this.#startDate.month) {
|
|
1841
|
-
month = this.#startDate.month;
|
|
1842
|
-
year = this.#startDate.year;
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
if (this.minDate) {
|
|
1846
|
-
if (year < this.minDate.year || year == this.minDate.year && month < this.minDate.month) {
|
|
1847
|
-
month = this.minDate.month;
|
|
1848
|
-
year = this.minDate.year;
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
if (this.maxDate) {
|
|
1852
|
-
if (year > this.maxDate.year || year == this.maxDate.year && month > this.maxDate.month) {
|
|
1853
|
-
month = this.maxDate.month;
|
|
1854
|
-
year = this.maxDate.year;
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
if (isLeft) {
|
|
1858
|
-
this.leftCalendar.month = this.leftCalendar.month.set({ year, month });
|
|
1859
|
-
if (this.linkedCalendars)
|
|
1860
|
-
this.rightCalendar.month = this.leftCalendar.month.plus({ month: 1 });
|
|
1861
|
-
} else {
|
|
1862
|
-
this.rightCalendar.month = this.rightCalendar.month.set({ year, month });
|
|
1863
|
-
if (this.linkedCalendars)
|
|
1864
|
-
this.leftCalendar.month = this.rightCalendar.month.minus({ month: 1 });
|
|
1865
|
-
}
|
|
1866
|
-
this.updateCalendars();
|
|
1867
|
-
}
|
|
1868
|
-
/**
|
|
1869
1820
|
* User clicked a time
|
|
1870
1821
|
* @param {external:jQuery} e - The Event target
|
|
1871
1822
|
* @emits "timeChange.daterangepicker"
|
|
@@ -1924,6 +1875,65 @@ class DateRangePicker {
|
|
|
1924
1875
|
this.element.trigger("timeChange.daterangepicker", [this, this.singleDatePicker ? null : side]);
|
|
1925
1876
|
}
|
|
1926
1877
|
/**
|
|
1878
|
+
* Calender month moved
|
|
1879
|
+
* @param {external:jQuery} e - The Event target
|
|
1880
|
+
* @private
|
|
1881
|
+
*/
|
|
1882
|
+
monthOrYearChanged(e) {
|
|
1883
|
+
var isLeft = $(e.target).closest(".drp-calendar").hasClass("left"), leftOrRight = isLeft ? "left" : "right", cal = this.container.find(".drp-calendar." + leftOrRight);
|
|
1884
|
+
var month = parseInt(cal.find(".monthselect").val(), 10);
|
|
1885
|
+
var year = cal.find(".yearselect").val();
|
|
1886
|
+
if (!isLeft) {
|
|
1887
|
+
if (year < this.#startDate.year || year == this.#startDate.year && month < this.#startDate.month) {
|
|
1888
|
+
month = this.#startDate.month;
|
|
1889
|
+
year = this.#startDate.year;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
if (this.minDate) {
|
|
1893
|
+
if (year < this.minDate.year || year == this.minDate.year && month < this.minDate.month) {
|
|
1894
|
+
month = this.minDate.month;
|
|
1895
|
+
year = this.minDate.year;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
if (this.maxDate) {
|
|
1899
|
+
if (year > this.maxDate.year || year == this.maxDate.year && month > this.maxDate.month) {
|
|
1900
|
+
month = this.maxDate.month;
|
|
1901
|
+
year = this.maxDate.year;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
if (isLeft) {
|
|
1905
|
+
this.leftCalendar.month = this.leftCalendar.month.set({ year, month });
|
|
1906
|
+
if (this.linkedCalendars)
|
|
1907
|
+
this.rightCalendar.month = this.leftCalendar.month.plus({ month: 1 });
|
|
1908
|
+
} else {
|
|
1909
|
+
this.rightCalendar.month = this.rightCalendar.month.set({ year, month });
|
|
1910
|
+
if (this.linkedCalendars)
|
|
1911
|
+
this.leftCalendar.month = this.rightCalendar.month.minus({ month: 1 });
|
|
1912
|
+
}
|
|
1913
|
+
this.updateCalendars();
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* User clicked `Apply` button
|
|
1917
|
+
* @emits "apply.daterangepicker"
|
|
1918
|
+
* @private
|
|
1919
|
+
*/
|
|
1920
|
+
clickApply() {
|
|
1921
|
+
this.hide();
|
|
1922
|
+
this.element.trigger("apply.daterangepicker", this);
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* User clicked `Cancel` button
|
|
1926
|
+
* @emits "cancel.daterangepicker"
|
|
1927
|
+
* @private
|
|
1928
|
+
*/
|
|
1929
|
+
clickCancel() {
|
|
1930
|
+
this.#startDate = this.oldStartDate;
|
|
1931
|
+
this.#endDate = this.oldEndDate;
|
|
1932
|
+
this.hide();
|
|
1933
|
+
this.element.trigger("cancel.daterangepicker", this);
|
|
1934
|
+
}
|
|
1935
|
+
/* #endregion */
|
|
1936
|
+
/**
|
|
1927
1937
|
* Update the picker with value from `<input>` element.<br>
|
|
1928
1938
|
* Input values must be given in format of `locale.format`. Invalid values are handles by `violated.daterangepicker` Event
|
|
1929
1939
|
* @emits "inputChanged.daterangepicker"
|