getting-started.md

December 19, 2019 ยท View on GitHub

v4.0.0 Migration Guide

In v4.0.0, jQuery is removed. It might cause other components to fail if they pass a jQuery object as a container.

Previously, you can use a jQuery to create an instance.

// v3
var instance = new tui.DatePicker($('#datepicker-wrapper'), {
   // options
});

Now, you have to use selector or HTMLElement as a container.

// v4
var instance = new tui.DatePicker('#datepicker-wrapper', {
   // options
});

// or

var container = document.getElementById('datepicker-wrapper');
var instance = new tui.DatePicker(container, {
    // options
});

Load dependency files

<html>
    <head>
        ....
        <link href="tui-time-picker.css" rel="stylesheet">
        <link href="tui-date-picker.css" rel="stylesheet">
    </head>
    <body>
        ....
        <script type="text/javascript" src="tui-time-picker.js"></script>
        <script type="text/javascript" src="tui-date-picker.js"></script>
        ....
    </body>
</html>

Write a wrapper element

<div id="datepicker-wrapper"></div>

Create instance

var instance = new tui.DatePicker('#datepicker-wrapper', {
   // options
});

Options

Datepicker

  • language (default 'en')
    • There are two supporting types by default - 'en' and 'ko'.
    • For custom texts - See the Datepicker.localeTexts
    • If set both calendar-language and datepicker-language, will apply datepicker-language first.
  • showAlways (default false)
    • If true, the datepicker will not close until you call "close()".
  • autoClose (default true)
    • If true, Close datepicker when select date
  • date (nullable)
    • Date instance or Timestamp for initial date
  • input
    • Set to bind input element
    • ex) {input: '#datepicker-input', format: 'yyyy-MM-dd'}
    • See the Date-Time text format
  • type (default 'date')
    • Type of picker - 'date', 'month', year'
    • See examples in API page
  • selectableRanges
    • Set selectable dates of datepicker
    • 2d-Array: [[startDate1, endDate1], [startDate2, endDate2], ...]
  • openers
    • Bind buttons to auto toggle(open-close) datepicker
    • Array of elements: ex) ['#opener1', '#opener2', ..]
  • calendar
  • timepicker

Calendar

  • language (default 'en')
    • There are two supporting types by default - 'en' and 'ko'.
    • For custom texts - See the Calendar.localeTexts
  • showToday (default true)
    • If true, calendar shows today
  • showJumpButtons
    • If true, 'date'-type calendar shows jump buttons (prev-year, next-year)
  • date
    • Date instance for initial date
  • type
    • Type of calendar - 'date', 'month', 'year'

Timepicker

  • initialHour (default 0)
  • initialMinute (default 0)
  • showMeridiem (default true)
    • If true, shows 'AM'/'PM' selector.
  • inputType (defalult selectbox)
    • Input types 'selectbox' or 'spinbox'

Date-Time text format

FormatDescExample
yyyy / YYYYYear2016, 2017, 2018, ...
y / yy / Y / YYYear16, 17, 18, ...
MMonth1, 2, 3, ...
MMMonth01, 02, 03, ...
MMMMonth - StrJan, Feb, Mar, ...
MMMMMonth - StrJanuary, February, March, ...
dDay in month1, 2, 3, ...
ddDay in month01, 02, 03, ...
DDay in week - StrSun, Mon, Tue, ...
DDDay in week - StrSunday, Monday, Tuesday, ...
h/HHour1, 2, 3, ...
hh/HHHour01, 02, 03, ...
mMinute1, 2, 3, ...
mmMinute01, 02, 03, ...
AMeridiem-Uppercase'AM', 'PM'
aMeridiem-Lowercase'am', 'pm'