2.4.0 • Published 12 months ago

thedatepicker v2.4.0

Weekly downloads
9
License
MIT
Repository
github
Last release
12 months ago

npm.io npm.io npm.io npm.io npm.io

TheDatepicker

Highly customizable pure JavaScript Datepicker by Slevomat.cz.

Try DEMO
Playground

  • Pure (Vanilla) javascript, no dependencies
  • Responsive (fullscreen on mobile devices)
  • Appropriate semantics - rendered into <table>
  • Accessible - Can be fully handled by keyboard only; only and only clickable elemets are always <a>; includes ARIA labels
  • Listeners for any event (open / close / (de)select / monthChange / focus)
  • Customizable design - all logical elements has it's predefined CSS classes; simply stylize weekend days, current day, past days, etc... (just examine datepicker HTML by DevTools to see predefined classes)
  • Possible to place it to a custom <div> or just let it float under an <input>
  • Darkmode

Installation:

Download:

https://github.com/thedatepicker/thedatepicker/releases/latest
Link dist/the-datepicker.min.js and dist/the-datepicker.css in your HTML.

NPM:

npm i thedatepicker

CDN:

https://cdn.jsdelivr.net/npm/thedatepicker@latest/dist/the-datepicker.min.js
https://cdn.jsdelivr.net/npm/thedatepicker@latest/dist/the-datepicker.css

Usage:

<html>
    <head>
        <script src="dist/the-datepicker.min.js"></script>
        <link rel="stylesheet" href="dist/the-datepicker.css">
    </head>
    
    <body>
        <input type="text" id="my-input">
    </body>
    
    <script>
        const input = document.getElementById('my-input');
        const datepicker = new TheDatepicker.Datepicker(input);
        datepicker.render();
    </script>
</html>

Customize:

TheDatepicker.Datepicker constructor accepts two arguments. First is an instance of an input element, second is an instance of a container element. Both are optional, but at least one must be present.

For example ...

<div id="my-container"></div>

<script>
const container = document.getElementById('my-container');
const datepicker = new TheDatepicker.Datepicker(null, container);
datepicker.render();
</script>

... will render the datepicker into the given <div>.

Options:

To see bunch of possible settings, visit https://thedatepicker.github.io/thedatepicker/

For example:

datepicker.options.setMinDate('today');

datepicker.options.setInputFormat('d M Y'); // "03 Mar 2022"

datepicker.options.setHideOnBlur(false);

datepicker.options.setAllowEmpty(false);

datepicker.options.onSelect(function (event, day) {
    alert('Selected ' + (day ? day.getFormatted() : 'NONE'));
});

datepicker.options.addDateAvailabilityResolver(function (date) {
    return date.getDay() !== TheDatepicker.DayOfWeek.Saturday
        && date.getDay() !== TheDatepicker.DayOfWeek.Sunday
});

datepicker.options.setGoBackHtml('<img src=back.png>');

// and much more...
  • Some options take effect only if changed before the first datepicker open.
  • Learn more about options in source code (setters are commented, search for public set*, public add*, public on*).
  • Do not forget to call datepicker.render() to start using datepicker.
  • Changing options after render takes effect immediately only if you call datepicker.render() again.
2.4.0

12 months ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.6

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.5

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.1.0

3 years ago

1.2.0

4 years ago

2.0.0-alpha.0

3 years ago

2.0.0-alpha.1

3 years ago

1.2.0-beta.0

4 years ago

1.3.0-alpha.0

4 years ago

1.1.1-alpha.0

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.2.0-alpha.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.8.0-beta.0

5 years ago

0.7.0

5 years ago

0.7.0-beta

5 years ago

0.6.0

5 years ago

0.5.5

5 years ago

0.5.5-alpha

5 years ago

0.5.5-beta

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.1-alpha

5 years ago

0.5.0

5 years ago

0.4.9

5 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago