new DatePicker(container, options)index.jsline 168
Create a date picker.
PARAMETERS
Name Type Description container
HTMLElementstring
Container element or selector of DatePicker
options
[ Object ]
Options
PROPERTIES
Name Type Description date
Datenumber = null
Initial date. Set by a Date instance or a number(timestamp). (default: no initial date)
type
'date''month''year' = 'date'
DatePicker type. Determine whether to choose a date, month, or year.
language
string = 'en'
Language code. English('en') and Korean('ko') are provided as default. To set to the other languages, use DatePicker.localeTexts.
timePicker
[ objectboolean ]
TimePicker options. Refer to the TimePicker instance's options. To create the TimePicker without customization, set to true.
calendar
[ object ]
Calendar options. Refer to the Calendar instance's options.
input
[ object ]
Input option
PROPERTIES
Name Type Description element
[ HTMLElementstring ]
Input element or selector
format
string = 'yyyy-mm-dd'
Format of the Date string
selectableRanges
Array.<Array.<Datenumber>> = 1900/1/1~2999/12/31
Ranges of selectable date. Set by Date instances or numbers(timestamp).
openers
Array.<HTMLElementstring> = []
List of the openers to open the DatePicker (example - icon, button, etc.)
showAlways
boolean = false
Show the DatePicker always
autoClose
boolean = true
Close the DatePicker after clicking the date
usageStatistics
boolean = true
Send a hostname to Google Analytics (default: true)
EXAMPLES
import DatePicker from 'tui-date-picker' // ES6 // const DatePicker = require('tui-date-picker'); // CommonJS // const DatePicker = tui.DatePicker; const range1 = [new Date(2015, 2, 1), new Date(2015, 3, 1)]; const range2 = [1465570800000, 1481266182155]; // timestamps const picker1 = new DatePicker('#datepicker-container1', { showAlways: true }); const picker2 = new DatePicker('#datepicker-container2', { showAlways: true, timePicker: true }); const picker3 = new DatePicker('#datepicker-container3', { language: 'ko', calendar: { showToday: true }, timePicker: { showMeridiem: true, defaultHour: 13, defaultMinute: 24 }, input: { element: '#datepicker-input', format: 'yyyy년 MM월 dd일 hh:mm A' } type: 'date', date: new Date(2015, 0, 1) selectableRanges: [range1, range2], openers: ['#opener'] });
Static Properties
localeTexts:
object
index.jsline 201Locale text data. English('en') and Korean('ko') are provided as default.
EXAMPLES
DatePicker.localeTexts['customKey'] = { titles: { // days DD: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // daysShort D: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // months MMMM: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], // monthsShort MMM: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, titleFormat: 'MMM yyyy', todayFormat: 'D, MMMM dd, yyyy', date: 'Date', time: 'Time' }; const datepicker = new DatePicker('#datepicker-container', { language: 'customKey' });
Static Methods
createCalendar(wrapperElement, options)index.jsline 31
Create a calendar.
PARAMETERS
Name Type Description wrapperElement
HTMLElementstring
Container element or selector of the Calendar
options
[ Object ]
Calendar options. Refer to the Calendar instance's options.
RETURNS:
{Calendar
}EXAMPLES
const calendar = DatePicker.createCalendar('#calendar-wrapper', { language: 'en', showToday: true, showJumpButtons: false, date: new Date(), type: 'date' });
createRangePicker(options)index.jsline 60
Create a date-range picker.
PARAMETERS
Name Type Description options
object
DateRangePicker options. Refer to the DateRangePicker instance's options.
RETURNS:
{DateRangePicker
}EXAMPLES
const rangepicker = DatePicker.createRangePicker({ startpicker: { input: '#start-input', container: '#start-container' }, endpicker: { input: '#end-input', container: '#end-container' }, type: 'date', format: 'yyyy-MM-dd' selectableRanges: [ [new Date(2017, 3, 1), new Date(2017, 5, 1)], [new Date(2017, 6, 3), new Date(2017, 10, 5)] ] });
Instance Methods
changeLanguage(language)index.jsline 1373
Change language.
SEES
- To set to the other languages, use DatePicker.localeTexts.
PARAMETERS
Name Type Description language
string
Language code. English('en') and Korean('ko') are provided as default.
removeRange(start, end, type)index.jsline 906
Remove a range. Use Date instances or numbers(timestamp).
PARAMETERS
Name Type Description start
Datenumber
the start date
end
Datenumber
the end date
type
null'date''month''year'
Range type. If falsy, start and end values are considered as timestamp
EXAMPLES
const start = new Date(2015, 1, 3); const end = new Date(2015, 2, 6); datepicker.removeRange(start, end);
setDateFormat(format)index.jsline 1192
Select the date by the date string format.
PARAMETERS
Name Type Description format
[ String ]
Date string format
EXAMPLES
datepicker.setDateFormat('yyyy-MM-dd'); datepicker.setDateFormat('MM-dd, yyyy'); datepicker.setDateFormat('yy/M/d'); datepicker.setDateFormat('yy/MM/dd');
setInput(element, options)index.jsline 1247
Set the input element
PARAMETERS
Name Type Description element
stringHTMLElement
Input element or selector
options
[ object ]
Input option
PROPERTIES
Name Type Description format
string = prevInput.format
Format of the Date string in the input
syncFromInput
boolean = false
Whether set the date from the input
setRanges(ranges)index.jsline 854
Set selectable ranges. Previous ranges will be removed.
PARAMETERS
Name Type Description ranges
Array.<Array.<Datenumber>>
Selectable ranges. Use Date instances or numbers(timestamp).
EXAMPLES
datepicker.setRanges([ [new Date(2017, 0, 1), new Date(2018, 0, 2)], [new Date(2015, 2, 3), new Date(2016, 4, 2)] ]);
Events
changeindex.jsline 1149
Occur after the selected date is changed.
SEES
- datepicker.on() to bind event handlers.
- datepicker.off() to unbind event handlers.
- Refer to CustomEvents from tui-code-snippet for more methods. DatePicker mixes in the methods from CustomEvents.
EXAMPLES
// bind the 'change' event datepicker.on('change', function() { console.log(`Selected date: ${datepicker.getDate()}`); }); // unbind the 'change' event datepicker.off('change');
closeindex.jsline 1074
Occur after the date picker closes.
SEES
- datepicker.on() to bind event handlers.
- datepicker.off() to unbind event handlers.
- Refer to CustomEvents from tui-code-snippet for more methods. DatePicker mixes in the methods from CustomEvents.
EXAMPLES
// bind the 'close' event datepicker.on('close', function() { alert('close'); }); // unbind the 'close' event datepicker.off('close');
drawindex.jsline 715
Occur after the calendar is drawn.
SEES
- datepicker.on() to bind event handlers.
- datepicker.off() to unbind event handlers.
- Refer to CustomEvents from tui-code-snippet for more methods. DatePicker mixes in the methods from CustomEvents.
PROPERTIES
Name Type Description date
Date
Calendar date
type
'date''month''year'
Calendar type
dateElements
Array.<HTMLElement>
elements for dates
EXAMPLES
// bind the 'draw' event datepicker.on('draw', function(event) { console.log(`Draw the ${event.type} calendar and its date is ${event.date}.`); }); // unbind the 'draw' event datepicker.off('draw');
openindex.jsline 998
Occur after the date picker opens.
SEES
- datepicker.on() to bind event handlers.
- datepicker.off() to unbind event handlers.
- Refer to CustomEvents from tui-code-snippet for more methods. DatePicker mixes in the methods from CustomEvents.
EXAMPLES
// bind the 'open' event datepicker.on('open', function() { alert('open'); }); // unbind the 'open' event datepicker.off('open');
