Modern Bootstrap Date Picker With jQuery And Day.js

File Size: 16.9 KB
Views Total: 6833
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Modern Bootstrap Date Picker With jQuery And Day.js

A fast, customizable, and modern-looking date picker component for Bootstrap 4 framework, built with jQuery and Day.js.

Features:

  • Custom date fomart.
  • Allows you to specify min/max dates.
  • Year & Month selector.
  • Auto disables the date picker on mobile.
  • Based on Bootstrap's Popover component.

How to use it:

1. Load the necessary jQuery library, Day.js, Bootstrap framework, and Font Awesome iconic font in the document.

<!-- Bootstrap + jQuery -->
<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/cdn/bootstrap.min.js"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="/path/to/cdn/fontawesome.min.css" />
<!-- Day.js -->
<script src="/path/to/cdn/dayjs.min.js"></script>

2. Download and load the datepicker-bs4.js script after jQuery.

<script src="js/datepicker-bs4.js" defer="defer"></script>

3. Initialize the plugin on the date picker input and done.

<input type="text" id="example" class="form-control" name="example" />
document.addEventListener('DOMContentLoaded', function () {
  jQuery('#example').datepicker({
    // options here
  });
});

4. Set the min/max dates (also called start/end dates) using either input's min/max attributes.

<input type="text" id="example" class="form-control" min="2000-01-01" max="2025-12-31" name="example" />
// OR via JavaScript
jQuery('#example').datepicker({
  minDate: '1900-01-01',
  maxDate: null,
});

5. Customize the date format.

jQuery('#example').datepicker({
  format: 'MM/DD/YYYY',
});

6. Set the width of the date picker popover.

jQuery('#example').datepicker({
  popoverWidth: '19rem',
});

7. Set the theme of the date picker: "dark", "light", or "auto".

jQuery('#example').datepicker({
  scheme: 'light'
});

Changelog:

2024-02-25

  • Bugfix

2024-01-06

  • Make placement of popover a bit more dynamic

2023-12-26

  • Rename theme to scheme

2023-11-25

  • Expose default options so that they can be overridden

2023-11-23

  • Fix to handle when minDate and maxDate options are invalid

2023-10-19

  • Switch default theme from auto to light

2023-10-17

  • Add a theme option to allow manual selection of dark/light mode

2023-10-16

  • Add missing style for dark mode

2023-09-06

  • Switch to using let and const

2023-08-26

  • Remove minScreenWidth option so that it can be handled by the user instead

2023-05-30

  • Bugfix

2022-11-28

  • Bugfix

2022-07-25

  • Trigger date picker on mobile

2022-07-22

  • Process options for ipad/iphone usage

2022-03-30

  • Fix to re-trigger change event if date is cleared out due to being outside max/min range

2021-12-02

  • Move lines around to avoid re-initializing same input field twice

2021-11-06

  • Adjust padding for month dropdown to avoid shifting navigation buttons

2021-10-26

  • Adjust padding to account for bold drop down toggles

2021-10-23

  • Use strict

This awesome jQuery plugin is developed by lesilent. For more Advanced Usages, please check the demo page or visit the official website.