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>
- Type:
Element
- Default:
null
Bind the datepicker to a form field
- Type:
Element
- Default:
null
If exists then end of date range will set here.
- Type:
Number
- Default:
1
ISO day of the week (1: Monday, ..., 7: Sunday).
- Type:
String
- Default:
body
Selector of the parent element that the date range picker will be added to, if not provided this will be 'body'.
- Type:
String
- Default:
auto
Language code for names of days, months by Date.prototype.toLocaleString(). 'auto' will try detect user browser language.
- Type:
String
- Default:
DD/MM/YYYY
The default output format.
- Type:
String
- Default:
-
Separator between dates when one field.
- Type:
Number
- Default:
1
Number of visible months.
- Type:
Number
- Default:
2
Number of columns months.
- Type:
Boolean
- Default:
true
Choose a single date instead of a date range.
- Type:
Boolean
- Default:
true
Close calendar when picked date/range.
- Type:
Boolean
- Default:
true
Close calendar when clicked outside the elements specified in field
or parentEl
. Recommended use when autoclose
is set to false
.
- Type:
Boolean
- Default:
false
Repick start/end instead of new range. This option working only when exists secondField
.
- Type:
moment|String|Number|Date
- Default:
null
The minimum/earliest date that can be selected. Any format: moment() or '2018-06-01' or 1527811200000, new Date()
- Type:
moment|String|Number|Date
- Default:
null
The maximum/latest date that can be selected. Any format: moment() or '2018-06-01' or 1527811200000, new Date()
- Type:
Array
- Default:
null
Array of disabled dates. Array can contains ranges, allowed the same format as in options minDate, maxDate. Eg.: \[moment().startOf('month'), \['2018-06-23', '2018-06-30'\]\]
- Type:
Boolean
- Default:
false
Select second date after the first selected date.
- Type:
Boolean
- Default:
false
Select second date before the first selected date.
- Type:
Number
- Default:
null
The minimum days of the selected range.
- Type:
Number
- Default:
null
The maximum days of the selected range.
- Type:
Boolean
- Default:
true
Show tooltip.
- Type:
Boolean|String
- Default:
false
Footer calendar, if set to true
will use default footer (Reset/Apply buttons) or custom string (html).
- Type:
Boolean
- Default:
true
If set to false
then will reset selected range when disabled dates exists in selected range.
- Type:
Boolean
- Default:
false
Calc date range in nights. (For hotels when last date doesn't include to range)
- Type:
String
- Default:
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”.
- Type:
Boolean
- Default:
false
Disable Saturday and Sunday.
- Type:
Object
- Default:
{
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
- Type:
Function
- Default:
null
Callback function for when a date is selected.
- Type:
Function
- Default:
null
Callback function for when the picker becomes visible.
- Type:
Function
- Default:
null
Callback function for when the picker is hidden.
- Type:
Function
- Default:
null
Working when disabledDatesInRange: false
Callback function for when user has select date range with disabled dates.
Set date when singleDate is true. date
can be moment, string, number, date.
Eg. picker.setDate(new Date());
Set date range. start, end
can be moment, string, number, date.
Eg. picker.setDateRange(new Date(), moment().add(7, 'day'));
array of disabled dates. Array can contains ranges, allowed moment, string, number, date.
Eg. picker.setDisableDates([ moment().startOf('month'), ['2018-06-23', '2018-06-30'] ]);
Return current date as moment object.
Return current start of date range as moment object.
Return current start of date range as moment object.
Returns the date in a string format.
Update picker options.
Make the picker visible.
Hide the picker.
Hide the picker and remove all event listeners.