Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pickmeup

nazar-pc10.7k0BSD3.2.1

Really simple, powerful, customizable and lightweight standalone datepicker

datepicker, date, calendar

readme

PickMeUp - Really simple, powerful, customizable and lightweight standalone datepicker

No dependencies, single/range/multiple selections, ability to put custom content into dates, very flexible styling and customization abilities.

Written and maintained by Nazar Mokrynskyi with the help of awesome contributors

Based on DatePicker by Stefan Petre

Browser support:

  • IE 10+
  • 2 latest stable versions of Firefox, Chromium, Opera and Edge

If you find this project useful, consider supporting its development on patreon.com/nazarpc, this would help me a lot!

Or if you are representing a company, here is Faircode page.

Demo

Getting started

You need only 2 files: dist/pickmeup.min.js and css/pickmeup.css.

The plugin can also be loaded as AMD or CommonJS module.

Then you can apply datepicker to any element:

pickmeup('.date');

Global default options are stored in pickmeup.defaults

They can be redefined during initialization:

pickmeup('.date', {
    format    : 'Y-m-d'
});

or with data-attributes with pmu- prefix:

<div class="date" data-pmu-format="Y-m-d"></div>

Twitter Bootstrap integration

For Twitter Bootstrap integration you do not need to include style file, but you need to include jquery.pickmeup.twitter-bootstrap.js instead, that will read settings of current Bootstrap theme and apply them to PickMeUp, so that it will look similar to native Bootstrap elements.

To apply integrated version use $(...).pickmeup_twitter_bootstrap() plugin for initialization:

$('.date').pickmeup_twitter_bootstrap();

All options and events are the same.

UIkit integration

For UIkit integration you do not need to include style file, but you need to include jquery.pickmeup.uikit.js instead, that will read settings of current UIkit theme and apply them to PickMeUp, so that it will look similar to native UIkit elements.

To apply integrated version use $(...).pickmeup_uikit() plugin for initialization:

$('.date').pickmeup_uikit();

All options and events are the same.

Configuration options

Option Value type Default Description
date array/number/object/string new Date Selected date after initialization. Can be single date string/object or array depending on selection mode
default_date boolean true If false will keep empty value until date selected
current number/object/string date Represents date that will be in the center of rendered calendar, defaults to date option's value
flat boolean false Whatever if the date picker is appended to the element or triggered by an event
first_day 0/1 1 First day of week: 0 - Sunday, 1 - Monday
prev string Previous button content
next string Next button content
mode single/multiple/range single Date selection mode
select_day boolean true Allow or deny days selection
select_month boolean true Allow or deny months selection
select_year boolean true Allow or deny year selection
view days/months/years days View mode after initialization
calendars int 1 Number of calendars, that will be rendered
format string d-m-Y Date format (aAbBCdeHIjklmMpPsSuwyY are supported)
title_format string/function B, Y Date format for calendar title in days view (aAbBCdeHIjklmMpPsSuwyY are supported). If function, must return the full title as a string. The date and locale are provided as parameters.
position top/right/bottom/left/function bottom Date picker's position relative to the triggered element, if function - must return an object with left and top keys and include units
class_name string | Class to be added to root datepicker element
hide_on_select boolean false If true - datepicker will be hidden after selection (for range mode allows to select first and last days)
min number/object/string | Min date available for selection
max number/object/string | Max date available for selection
separator string - Is used for joining separate dates in multiple mode and first/last dates in range mode
locale string en String, that specifies current locale.
locales object see Localization Key-value object, where keys are locales and values contain localized days of week names and months
render function | Executed for each day element rendering, takes date argument, allows to select, disable or add class to element
instance_template function (look at source code) Responsible for rendering simple PickMeUp instance with header and days of weeks
instance_content_template function (look at source code) Responsible for rendering instance content container (which contains years, months or days)
Selecting/disabling dates with custom logic

render options might return object with any of following keys:

  • selected: if true - date will be selected
  • disabled: if true - date will be disabled
  • class_name: will be added to class of day element

Example:

var now = new Date;
pickmeup(element, {
    render : function (date) {
        if (date < now) {
            return {disabled : true, class_name : 'date-in-past'};
        }
        return {};
    } 
})

Events callbacks

In PickMeUp events are native DOM events fired on element when pickmeup() was called and always have pickmeup- prefix.

pickmeup-change

Triggered at date change. Example:

pickmeup(element);
element.addEventListener('pickmeup-change', function (e) {
    console.log(e.detail.formatted_date); // New date according to current format
    console.log(e.detail.date);           // New date as Date object
})
pickmeup-show

Triggered at showing. Example:

pickmeup(element);
element.addEventListener('pickmeup-show', function (e) {
    e.preventDefault(); // Showing can be canceled if needed
})
pickmeup-hide

Triggered at hiding. Example:

pickmeup(element);
element.addEventListener('pickmeup-hide', function (e) {
    e.preventDefault(); // Hiding can be canceled if needed
})
pickmeup-fill

Triggered after filling of PickMeUp container with new markup of days, months, years. May be needed for inner datepicker markup editing.

pickmeup(element);
element.addEventListener('pickmeup-fill', function (e) {
    // Do stuff here
})

Methods

Methods allows external control on datepicker

Hide
pickmeup('.date').hide();
Show
pickmeup('.date').show();
Prev
pickmeup('.date').prev();
Next
pickmeup('.date').next();
Get date
pickmeup('.date').get_date(formatted);

formatted - boolean or string (default false)

  • false - Date object
  • true - string formatted in accordance with format option
  • string is used to specify custom format instead if given during initialization
Set date
pickmeup('.date').set_date(new Date);

date - can be single date string/object or array depending on selection mode

Clear multiple selection
pickmeup('.date').clear();
Update datepicker
pickmeup('.date').update();
Destroy datepicker

Destroys PickMeUp instance, removes created markup, restores everything that was changed to original state.

pickmeup('.date').destroy();

Localization

You can add locales to global defaults and then use different locales in particular instance with locale option. Sample object for English language (no need to add, already included in source code):

pickmeup.defaults.locales['en'] = {
    days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
    months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
};

Russian:

pickmeup.defaults.locales['ru'] = {
    days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
    daysShort: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
    daysMin: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
    months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
    monthsShort: ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']
};

Other

Current options (for whatever reason) can be accessed as element.__pickmeup.options.

Root pickmeup element can be accessed as element.__pickmeup.element.

Styling

If you want other colors - just change several variables in scss file.

To change size - adjust font-size for root datepicker element, everything will scale nicely.

Contribution

Feel free to create issues and send pull requests, they are highly appreciated!

Before reporting an issue, be so kind to prepare reproducible example on jsfiddle.net, please.

You can start with working demo of latest stable version of PickMeUp: jsfiddle.net/0kg5jL3p

License

Free Public License 1.0.0 / Zero Clause BSD License

https://opensource.org/licenses/FPL-1.0.0

https://tldrlegal.com/license/bsd-0-clause-license

changelog

3.2.1 (19 January, 2019)

  • fix for parsing dates consisting of timestamps

3.2.0 (07 December, 2018)

  • title_format can now be a function, allowing more customization

3.1.3 (06 March, 2018)

  • Fix top and left positions that were working incorrectly because of hidden root element

3.1.2 (20 February, 2018)

  • Fix for j formatting option

3.1.0 (13 February, 2018)

  • License changed from MIT to 0BSD
  • Removed Bower support, use NPM instead
  • CoffeeScript files converted to LiveScript
  • Added support for customizing position by specifying custom function as position option

3.0.11 (07 November, 2017)

  • Fix for selected is not defined

3.0.10 (07 November, 2017)

  • Fix parsing dates with custom locale for days of the week

3.0.9 (08 October, 2017)

  • Fix for disabled and selected in render callback didn't work with false
  • Fix for Summer/Winter time preventing dates from being shown as selected

3.0.8 (16 November, 2016)

  • Fix for removing own event listeners during destroying, fixes #153

3.0.7 (11 November, 2016)

  • Fixed main file (PR #142)
  • Do not fail with exception when target element to initialize PickMeUp not found, fixes #148
  • Fix for Twitter Bootstrap and UIkit wrappers (caused by changes in PickMeUp internals), fixes #138

3.0.6 (15 September, 2016)

  • IE compatibility fix

3.0.5 (09 September, 2016)

  • Remove .idea from npm package
  • Small fix for getting locales when parsing date
  • Remove mentioning support for Opera 12.1 (didn't check it for a long time and never will)
  • Fix for error when no options specified during initialization
  • Fix for events being dispatched on instance element, rather than on target element, where PickMeUp was initialized, fixes #134
  • Fix for strange issue when showing datepicker in click event handler of another element didn't work, fixes #135
  • Fix for non-flat datepicker was closed immediately in range mode, fixes #136

3.0.0 (02 September, 2016)

  • PickMeUp is now standalone, no jQuery needed
  • .pmu-flat and .pmu-hidden classes added
  • Events are now native DOM events instead of callbacks in options
  • Changing date in input field will immediately affect datepicker
  • Defaults moved from $.pickmeup to pickmeup.defaults
  • Internals (runtime options, events, etc.) are stored in element.__pickmeup
  • before_show event removed as redundant
  • Days/months/years rendering is now done in form of elements, which allows to customize contents in any possible way, while necessary data are stored in private properties of those elements
  • New options instance_template and instance_content_template added
  • Stop patching Date.prototype, use local wrappers instead
  • trigger_event option was removed and styles adjusted to remove 300ms delay when clicking on touch devices
  • Added support for multiple languages with ability to choose during initialization (using newly added option locales and changed option locale)
  • Added gulp task for building minified file
  • Files re-structuring
  • Refactoring and smaller bug fixes
  • Minified source become even smaller!

2.10.0 (31 August, 2016)

  • Refactoring to set_date during initialization instead of duplicating code
  • Added new option current, represents date that will be in the center of rendered calendar
  • Fix for #41 (do not move months back and forth when selecting days)
  • Refactoring towards unification and normalization (dates as Date objects)
  • Fix for #97 and generally for setting date outside of limits
  • Fix for setting date to empty array, to address underlying problem in #121
  • Make sass variables 'default' (PR #313)
  • Tiny fix for show method being forced even when it shouldn't
  • Do not update <input> value unless value really changed to avoid cursor jumping
  • Small fixes

2.9.2 (05 August, 2016)

  • Fix for #120 (when applied to multiple elements options might be changed during initialization of one element and then used in another, fixed by deep copy of options)
  • Added support for numeric (Unix timestamp in milliseconds) dates

2.9.1 (24 June, 2016)

  • Fix for Twitter Bootstrap and UIkit integration didn't work properly, fixes #73
  • In case of multiple dates open on the last one instead of the first (seems more natural), fixes first part of #74
  • Added support for default: false for range and multiple modes, fixes second part of #74 and #89
  • Fire change event when filling empty input on on first open, fixes #77
  • Small fix for transparent in SCSS
  • Consistent use of namespaced events from configuration
  • Added information about touch devices support to readme

2.9.0 (04 February, 2016)

  • Added 'title_format' option
  • Added NPM support

2.8.0 (08 April, 2015)

  • Added support for no default date #70, thanks to Amar Syla for pull request!

2.7.0 (31 March, 2015)

  • Added UMD support #63, thanks to Przemysław Piątek for pull request!

2.6.5 (24 March, 2015)

  • Mobile Safari issue, fixes #50

2.6.4 (04 March, 2015)

  • Method 'set_date' does not update input value, fixes #53
  • Fix for input+range+hide_on_select, fixes #56
  • Fix for disabled dates + bootstrap, fixes #59

2.6.3 (21 January, 2015)

  • Protect modification of internal date in render event callback.
  • Fix for update event on flat: true instances.

2.6.2 (15 January, 2015)

  • Fix for bug when min and max were not specified and forced datepicker to stuck at 1970, fixes #49

2.6.1 (13 January, 2015)

  • Fix for bug when specified max date in the middle of the month caused inability to switch to that month

2.6.0 (13 December, 2014)

  • New parameter $background-hover added to scss style file
  • Fix wrong class on selected months and years (pmu-today instead of pmu-selected)
  • New default_date option
  • Fix for $background-hover default color
  • Fix for resetting interval to 1 date with combination of flat:false and hide_on_select:true

2.5.1 (08 September, 2014)

  • Single mode check if options.date is array (take first element of array) #35

2.5.0 (23 August, 2014)

  • Fix for The month before min date should not display #32
  • events namespacing
  • touch support (trigger_event option defaults to click touchstart)
  • destroy method, fixes #30
  • current date highlighting in range mode
  • new option select_day (also select_month no longer depends on select_year), fixes #29
  • account min/max options in months and years views
  • huge refactoring and fixes for various found small bugs
  • Fix for pmu-{next || prev} clicktarget unreachable with icon, issue #33

2.4.3 (05 August, 2014)

  • Fix for broken date parsing in last version

2.4.2 (16 July, 2014)

  • More correct fix for NaN instead of dates and months names when wrong data placed in input field

2.4.1 (11 July, 2014)

  • Fix for NaN instead of dates and months names when wrong data placed in input field, fixes #26 and #27

2.4.0 (01 July, 2014)

  • Add methods prev/next for external call

2.3.0 (29 June, 2014)

  • new options select_year and select_month
  • bower config added
  • New event fill event added
  • New scss parameter for color of selected date
  • UIkit integration
  • Fix for issue #20: Invoking clear in range mode
  • Fix for parsing formatted date when using months
  • Correct cyrillic and any other symbols support in months names
  • Added support of custom format in formatted argument for get_date method
  • Twitter Bootstrap integration
  • Hide previous/next buttons when necessary if min/max options specified, closes #17

2.2.3 (January 18, 2014)

  • Fix for issue #7: Doesn't close when focus is lost from input field
  • Fix for issue #8: NaN is appearing instead of numbers

2.2.2 (January 11, 2014)

  • update, get_date, set_date methods are not working

2.2.1 (January 08, 2014)

  • Fix for issue #4): Callbacks only apply to first of original selector

2.2.0 (January 08, 2014)

  • Automatic getting and setting value when applied to input (fixes issue #3)
  • New separator option.

2.1.2 (November 29, 2013)

  • Positioning fix

2.1.1 (November 25, 2013)

  • Fixed typo

2.1.0 (November 21, 2013)

  • Current day marked with class pmu-today and has its own color settings
  • Bad input ignored, today's date assumed
  • Disabled text selection
  • Arrows only on first and last calendars
  • New min and max options
  • New hide_on_select option

2.0.1 (November 21, 2013)

  • Large internal refactoring, hopefully code now is more clear, consistent and understandable.
  • this in any callback will be the same element, on which pickmeup() was called (actually, the same for internal functions).
  • Current options (for whatever reason) can be accessed as $('...').data('pickmeup-options').
  • Root pickmeup element (jQuery collection object) can be accessed as $('...').get(0).pickmeup or directly this.pickmeup if inside callback.

1.0.0 (November 16, 2013)

  • Initial release