Bootstrap Datepicker in Modal Popup Window

Yet another datepicker jQuery plugin easily used in Bootstrap modal popup. The plugin has multi options, multi functions and multi languages to pick current, selected or filtered date.


Plugin Overview

Plugin: datepicker-in-bootstrap-modal
Author: Fengyuan Chen
Licence: MIT Licence
Published: March 24, 2019
Repository: Fork on GitHub
Dependencies: jQuery 3.3.1 or Latest version, Bootstrap 4.1.3
File Type: zip archive (HTML, CSS & JavaScript)
Package Size: 38 KB

How to Use Datepicker in Bootstrap Modal:

1. To getting started with this plugin, load the jQuery and Bootstrap framework.

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<!-- Bootstrap Js -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>

2. After this, include the datepicker’s javascript and CSS files.

<!-- Datepicker CSS -->
<link rel="stylesheet" href="css/datepicker.css">

<!-- Datepicker JS-->
<script src="js/datepicker.js"></script>

3. To create Bootstrap datepicker in modal popup, so build the HTML structure like below.

 <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary" data-target="#modal" data-toggle="modal">
      Launch the demo
    </button>

    <!-- Modal -->
    <div class="modal fade" id="modal" role="dialog" aria-labelledby="modalLabel" tabindex="-1">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="modalLabel">Datepicker</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body" style="height: 1000px;">
            <input type="text" class="form-control" data-toggle="datepicker">
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
  </div>

4. Initialize the plugin in jQuery document ready function so that datepicker activated.

 $(function() {
   $('[data-toggle="datepicker"]').datepicker({
      autoHide: true,
      zIndex: 2048,
   });
});

Be the first to comment

Leave a Reply

Your email address will not be published.


*