Click on the button above to display the date picker. It appears under the input field. Select the date.
var datePicker = new DatePicker({ input: $('input'), trigger: $('button') }); datePicker.init();
Click on the button above to display the date picker. It appears under the input field. Select the date.
var datePicker = new DatePicker({ input: $('input'), trigger: $('button') }); datePicker.init();
In this example when you select date in first datepicker, it disables all earlier dates in the second datepicker. This example is useful in case when you want to select a date range.
Datepicker support gives you a possibility to extend its functionality without changing the source code.
Supported events or hooks:
var datePicker1 = new DatePicker({ input: $('#hw_example_input1'), trigger: $('#hw_example_button1'), events: { onSelect: function(e){ var currentButton = $(e.currentTarget); var minDate = new Date(); minDate.setTime(currentButton.attr("data-date")); datePicker2.minDate = minDate; if (datePicker2.currentPicker != null) { datePicker2.monthChange(minDate); } } } }); datePicker1.init(); var datePicker2 = new DatePicker({ input: $('#hw_example_input2'), trigger: $('#hw_example_button2'), events: { onSelect: function(e){ var currentButton = $(e.currentTarget); var maxDate = new Date(); maxDate.setTime(currentButton.attr("data-date")); datePicker1.maxDate = maxDate; if (datePicker1.currentPicker != null) { datePicker1.monthChange(maxDate); } } } }); datePicker2.init();
For some countries calendar starts with Monday and for other - with Sunday.
var datePicker = new DatePicker({ input: $('input'), trigger: $('button'), startWithMonday: true }); datePicker.init();
The example above is in ukrainian. Initially datepicker is in english. In the source code for this example I left original english translation even though the datepicker is in english. It was made to show you which parameters should be set.
var datePicker = new DatePicker({ input: $('input'), trigger: $('button'), i18n: { 'prevMonth': 'Previous month', 'nextMonth': 'Next month', 'monthName': [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], 'weekNameFull': [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ], 'weekNameShort': [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ], 'currentDate': 'Current date', 'selectedDate': 'Selected date', 'currentMonth': 'Current month', 'lastAvailableDate': 'Last available date', 'firstAvailableDate': 'First available date', 'notAvailable': 'Date is not available', 'description': 'datepicker', 'close': 'Close' } }); datePicker.init();
Dates which are out of range - disabled. You can not select them. Initially, datepicker accepts the date, which is out of range, but if you try to enter the date manually in the input field, it ignores that value.
If all dates of the previous month are disabled and there is no selected date at that month, appropriate navigation buttons are also disabled and you can not switch to that month.
var minDate = new Date(); minDate.setDate( minDate.getDate() - 60 ); var maxDate = new Date(); maxDate.setDate( maxDate.getDate() + 1 ); var selectedDate = new Date(); selectedDate.setDate( selectedDate.getDate() - 90 ); var datePicker = new DatePicker({ input: $('input'), trigger: $('button'), minDate: minDate, maxDate: maxDate }); datePicker.init();
By default date format is "dd.mm.yyyy". However datepicker support different date formats: mm/dd/yyyy, yyyy-m-d etc.
yyyy - is a 4 digit year, mm - 2 digits month, single m - 1 or 2 digits month, dd - 2 digits day, single d - 1 or 2 digits day.
var datePicker = new DatePicker({ input: $('input'), trigger: $('button'), formatDate: 'mm/dd/yyyy' }); datePicker.init();
Copyright © 2017 Dmytro Dzyuba. Software released under MIT License