Using Bootstrap DatetimePicker with Sweet Alert 2 - Display calendar over alert

Codewise picture Codewise · Aug 22, 2017 · Viewed 8.9k times · Source

I am using the SweetAlert2 dialog with a form inside. I want to use the Bootstrap DateTimePicker widget.

The calendar widget popup is displayed within the SweetAlert window instead of over top of it. This makes the alert expand and contract - and you must scroll inside the alert to see the calendar. The desired behavior is for the calendar to display as a child of the primary page and display over top of the alert.

https://jsfiddle.net/ghr2bwoc/13/

  swal({
    title: 'Date picker',
    html: '<input id="datepicker">',
    showConfirmButton: false,
    onOpen: function() {
        $('#datepicker').datetimepicker({});
    },

  }).then(function(result) {

  });

Answer

taekwondoalex picture taekwondoalex · Aug 25, 2017

Create an additional class in your style sheet:

.swal2-overflow {
  overflow-x: visible;
  overflow-y: visible;
}

Add this new class to your sweet alert code using the customClass attribute.

swal({
  title: 'Date picker',
  html: '<input id="datepicker">',
  showConfirmButton: false,
  customClass: 'swal2-overflow',
  onOpen: function() {
      $('#datepicker').datetimepicker({});
  },

}).then(function(result) {

});