Date Range Picker can be attached to input element to pop up one or more calendars for selecting dates.
npm install lightpick
or you can download and include Moment.js and Lightpick files manually.
Lightpick can be bound to an input field:
<input type="text" id="datepicker"/>
Include Lightpick script to the end of your document:
<link rel="stylesheet" type="text/css" href="css/lightpick.css">
...
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="lightpick.js"></script>
<script>
var picker = new Lightpick({ field: document.getElementById('datepicker') });
</script>
Default configuration
Option: singleDate = false
Option: secondField
Option: numberOfMonths = 6
Option: numberOfColumns = 3
Options: minDate, maxDate
Option: selectForward = true
Option: selectBackward = true
Options: minDays, maxDays
Option: repick
Options: lang: 'ru', custom locale
Options: footer: true
Options: inline: true
field
Element
null
Bind the datepicker to a form field
secondField
Element
null
If exists then end of date range will set here.
firstDay
Number
1
ISO day of the week (1: Monday, ..., 7: Sunday).
parentEl
String
body
Selector of the parent element that the date range picker will be added to, if not provided this will be 'body'.
lang
String
auto
Language code for names of days, months by Date.prototype.toLocaleString(). 'auto' will try detect user browser language.
format
String
DD/MM/YYYY
The default output format.
separator
String
-
Separator between dates when one field.
numberOfMonths
Number
1
Number of visible months.
numberOfColumns
Number
2
Number of columns months.
singleDate
Boolean
true
Choose a single date instead of a date range.
autoclose
Boolean
true
Close calendar when picked date/range.
hideOnBodyClick
Boolean
true
Close calendar when clicked outside the elements specified in field
or parentEl
. Recommended use when autoclose
is set to false
.
repick
Boolean
false
Repick start/end instead of new range. This option working only when exists `secondField`.
minDate
moment|String|Number|Date
null
The minimum/earliest date that can be selected. Any format: moment() or '2018-06-01' or 1527811200000, new Date()
maxDate
moment|String|Number|Date
null
The maximum/latest date that can be selected. Any format: moment() or '2018-06-01' or 1527811200000, new Date()
disableDates
Array
null
Array of disabled dates. Array can contains ranges, allowed the same format as in options minDate, maxDate.
Ex.: [moment().startOf('month'), ['2018-06-23', '2018-06-30']]
selectForward
Boolean
false
Select second date after the first selected date.
selectBackward
Boolean
false
Select second date before the first selected date.
minDays
Number
null
The minimum days of the selected range.
maxDays
Number
null
The maximum days of the selected range.
hoveringTooltip
Boolean
true
Show tooltip.
footer
Boolean|String
false
Footer calendar, if set to `true` will use default footer (Reset/Apply buttons) or custom string (html).
disabledDatesInRange
Boolean
true
If set to `false` then will reset selected range when disabled dates exists in selected range.
tooltipNights
Boolean
false
Calc date range in nights. (For hotels when last date doesn't include to range)
orientation
String
auto
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”.
disableWeekends
Boolean
false
Disable Saturday and Sunday.
inline
Boolean
false
Show calendar inline. If true
and parentEl
is not provided then will use parentNode
of field.
dropdowns
Object|Boolean
{
years: {
min: 1900,
max: null,
},
months: true,
}
Dropdown selections for years, months. Can be false
for disable both dropdowns.
years
(Object|Boolean) - Object must contains min
and max
range of years or can be false
for disable dropdown of years.
months
(Boolean) - true/false
for enable/disable dropdown of months.
locale
Object
{
buttons: {
prev: '←',
next: '→',
close: '×',
reset: 'Reset',
apply: 'Apply'
},
tooltip: {
one: 'day',
other: 'days'
},
tooltipOnDisabled: null,
pluralize: function(i, locale){
if (typeof i === "string") i = parseInt(i, 10);
if (i === 1 && 'one' in locale) return locale.one;
if ('other' in locale) return locale.other;
return '';
}
}
buttons
- Text for buttons
tooltip
- Text for tooltip (one, few, many, other)
tooltipOnDisabled
(String) - Show tooltip text on disabled dates. (Eg. «Already booked»)
pluralize
(function) - Function for calc plural text. More examples for another locales on betsol/numerous
onSelect
Function
null
Callback function for when a date is selected.
onOpen
Function
null
Callback function for when the picker becomes visible.
onClose
Function
null
Callback function for when the picker is hidden.
picker.setDate(date)
Set date when singleDate is true. date
can be moment, string, number, date.
Ex. picker.setDate(new Date());
picker.setDateRange(start, end)
Set date range. start, end
can be moment, string, number, date.
Ex. picker.setDateRange(new Date(), moment().add(7, 'day'));
picker.setDisableDates(array)
array of disabled dates. Array can contains ranges, allowed moment, string, number, date.
Ex. picker.setDisableDates([ moment().startOf('month'), ['2018-06-23', '2018-06-30'] ]);
picker.getDate()
Return current date as moment object.
picker.getStartDate()
Return current start of date range as moment object.
picker.getEndDate()
Return current start of date range as moment object.
picker.toString('YYYY-MM-DD')
Returns the date in a string format.
picker.reloadOptions({})
Update picker options.
picker.show()
Make the picker visible.
picker.hide()
Hide the picker.
picker.destroy()
Hide the picker and remove all event listeners.
Copyright 2019 Rinat G.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.