daterangepicker-4.x 4.2.3 → 4.2.4
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/README.md +5 -4
- package/daterangepicker.js +37 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ Above samples are based on the [original repository](https://github.com/dangross
|
|
|
18
18
|
```html
|
|
19
19
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
|
|
20
20
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script>
|
|
21
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.
|
|
22
|
-
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.
|
|
21
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.4/daterangepicker.min.js"></script>
|
|
22
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.4/daterangepicker.min.css" rel="stylesheet" />
|
|
23
23
|
|
|
24
24
|
<input type="text" id="daterange" />
|
|
25
25
|
|
|
@@ -114,6 +114,7 @@ Available methods are listed below in [API documentation](#DateRangePicker). You
|
|
|
114
114
|
* [.setStartDate(startDate)](#DateRangePicker+setStartDate)
|
|
115
115
|
* [.setEndDate(endDate)](#DateRangePicker+setEndDate)
|
|
116
116
|
* [.setPeriod(startDate, endDate)](#DateRangePicker+setPeriod)
|
|
117
|
+
* `$(...).data('daterangepicker')` to get the daterangepicker object
|
|
117
118
|
|
|
118
119
|
all other methods are used rarely.
|
|
119
120
|
|
|
@@ -494,7 +495,7 @@ Options for DateRangePicker
|
|
|
494
495
|
| 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](ISO-8601) or a string matching `locale.format`. |
|
|
495
496
|
| minSpan | [<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](ISO-8601) duration.<br/> Ignored when `singleDatePicker: true` |
|
|
496
497
|
| maxSpan | [<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](ISO-8601) duration.<br/> Ignored when `singleDatePicker: true` |
|
|
497
|
-
| 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`.
|
|
498
|
+
| 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](ISO-8601) or a string matching `locale.format`.<br/> When `initalMonth` is used, then `endDate` is ignored and it works only with `timePicker: false` |
|
|
498
499
|
| 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` |
|
|
499
500
|
| 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/> The start and end dates provided to your callback will be the same single date chosen. |
|
|
500
501
|
| showDropdowns | <code>boolean</code> | <code>false</code> | Show year and month select boxes above calendars to jump to a specific month and year |
|
|
@@ -511,7 +512,7 @@ Options for DateRangePicker
|
|
|
511
512
|
| 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. |
|
|
512
513
|
| 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 |
|
|
513
514
|
| 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/> Function has no effect on date values set by `startDate`, `endDate`, `ranges`, [setStartDate](#DateRangePicker+setStartDate), [setEndDate](#DateRangePicker+setEndDate). |
|
|
514
|
-
| 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: `
|
|
515
|
+
| 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/> Function has no effect on time values set by `startDate`, `endDate`, `ranges`, [setStartDate](#DateRangePicker+setStartDate), [setEndDate](#DateRangePicker+setEndDate).<br/> Ensure that your function returns `false` for at least one item. Otherwise the calender is not rendered.<br/> |
|
|
515
516
|
| 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)` |
|
|
516
517
|
| applyButtonClasses | <code>string</code> | <code>"btn-primary"</code> | CSS class names that will be added only to the apply button |
|
|
517
518
|
| cancelButtonClasses | <code>string</code> | <code>"btn-default"</code> | CSS class names that will be added only to the cancel button |
|
package/daterangepicker.js
CHANGED
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
* Must be a `luxon.Duration` or number of seconds or a string according to {@link ISO-8601} duration.<br/>
|
|
62
62
|
* Ignored when `singleDatePicker: true`
|
|
63
63
|
* @property {external:DateTime|external:Date|string|null} initalMonth - Default: `DateTime.now().startOf('month')`<br/>
|
|
64
|
-
* The inital month shown when `startDate: null`.
|
|
64
|
+
* The inital month shown when `startDate: null`. Be aware, the attached `<input>` element must be also empty.`<br/>
|
|
65
65
|
* Must be a `luxon.DateTime` or `Date` or `string` according to {@link ISO-8601} or a string matching `locale.format`.<br/>
|
|
66
66
|
* When `initalMonth` is used, then `endDate` is ignored and it works only with `timePicker: false`
|
|
67
67
|
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
* Function has no effect on date values set by `startDate`, `endDate`, `ranges`, {@link #DateRangePicker+setStartDate|setStartDate}, {@link #DateRangePicker+setEndDate|setEndDate}.
|
|
101
101
|
* @property {function} isInvalidTime=false - A function that is passed each hour/minute/second/am-pm in the two calendars before they are displayed,<br/>
|
|
102
102
|
* and may return `true` or `false` to indicate whether that date should be available for selection or not.<br/>
|
|
103
|
-
* Signature: `
|
|
103
|
+
* Signature: `isInvalidTime(time, side, unit)`<br/>
|
|
104
104
|
* `side` is `'start'` or `'end'` or `null` for `singleDatePicker: true`<br/>
|
|
105
105
|
* `unit` is `'hour'`, `'minute'`, `'second'` or `'ampm'`<br/>
|
|
106
106
|
* Hours are always given as 24-hour clock<br/>
|
|
@@ -435,16 +435,47 @@
|
|
|
435
435
|
if (this.maxDate)
|
|
436
436
|
this.maxDate = this.maxDate.endOf('day');
|
|
437
437
|
}
|
|
438
|
+
|
|
439
|
+
//if no start/end dates set, check if the input element contains initial values
|
|
440
|
+
if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
|
|
441
|
+
if ($(this.element).is(':text')) {
|
|
442
|
+
let start, end;
|
|
443
|
+
const val = $(this.element).val();
|
|
444
|
+
if (val != '') {
|
|
445
|
+
const split = val.split(this.locale.separator);
|
|
446
|
+
const format = typeof this.locale.format === 'string' ? this.locale.format : DateTime.parseFormatForOpts(this.locale.format);
|
|
447
|
+
if (split.length == 2) {
|
|
448
|
+
start = DateTime.fromFormat(split[0], format, { locale: DateTime.now().locale });
|
|
449
|
+
end = DateTime.fromFormat(split[1], format, { locale: DateTime.now().locale });
|
|
450
|
+
} else if (this.singleDatePicker) {
|
|
451
|
+
start = DateTime.fromFormat(val, format, { locale: DateTime.now().locale });
|
|
452
|
+
end = DateTime.fromFormat(val, format, { locale: DateTime.now().locale });
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (start.isValid && end.isValid) {
|
|
456
|
+
this.setStartDate(start, false);
|
|
457
|
+
this.setEndDate(end, false);
|
|
458
|
+
} else {
|
|
459
|
+
console.error(`Value in <input> is not a valid string`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
438
465
|
if (this.singleDatePicker) {
|
|
439
466
|
this.endDate = this.startDate;
|
|
440
467
|
} else if (this.endDate < this.startDate) {
|
|
441
468
|
this.endDate = this.startDate;
|
|
469
|
+
console.warn(`Set endDate to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} because it was earlier than startDate`);
|
|
442
470
|
}
|
|
443
|
-
if (!this.startDate && this.initalMonth)
|
|
444
|
-
this.endDate = null;
|
|
445
471
|
|
|
446
|
-
|
|
447
|
-
|
|
472
|
+
if (!this.startDate && this.initalMonth) {
|
|
473
|
+
// No initial date selected
|
|
474
|
+
this.endDate = null;
|
|
475
|
+
} else {
|
|
476
|
+
// Do some sanity checks on startDate for minDate, maxDate
|
|
477
|
+
this.constrainDate();
|
|
478
|
+
}
|
|
448
479
|
|
|
449
480
|
if (typeof options.applyButtonClasses === 'string')
|
|
450
481
|
this.applyButtonClasses = options.applyButtonClasses;
|
|
@@ -533,29 +564,6 @@
|
|
|
533
564
|
}
|
|
534
565
|
}
|
|
535
566
|
|
|
536
|
-
//if no start/end dates set, check if the input element contains initial values
|
|
537
|
-
if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
|
|
538
|
-
if ($(this.element).is(':text')) {
|
|
539
|
-
let start, end;
|
|
540
|
-
const val = $(this.element).val();
|
|
541
|
-
const split = val.split(this.locale.separator);
|
|
542
|
-
|
|
543
|
-
const format = typeof this.locale.format === 'string' ? this.locale.format : DateTime.parseFormatForOpts(this.locale.format);
|
|
544
|
-
if (split.length == 2) {
|
|
545
|
-
start = DateTime.fromFormat(split[0], format, { locale: DateTime.now().locale });
|
|
546
|
-
end = DateTime.fromFormat(split[1], format, { locale: DateTime.now().locale });
|
|
547
|
-
} else if (this.singleDatePicker && val !== "") {
|
|
548
|
-
start = DateTime.fromFormat(val, format, { locale: DateTime.now().locale });
|
|
549
|
-
end = DateTime.fromFormat(val, format, { locale: DateTime.now().locale });
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
if (start.isValid && end.isValid) {
|
|
553
|
-
this.setStartDate(start, false);
|
|
554
|
-
this.setEndDate(end, false);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
567
|
if (!this.singleDatePicker && typeof options.ranges === 'object') {
|
|
560
568
|
// Process custom ranges
|
|
561
569
|
for (let range in options.ranges) {
|