jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
360 stars 85 forks source link

Failure with bootstrap modals #15

Closed uberllama closed 10 years ago

uberllama commented 10 years ago

Hey guys, long day, might be missing something obvs.

I'm trying to use bootstrap datepicker, query timepicker, and datepair in a bootstrap modal and seeing weird behaviour.

My code looks likes this:

var renderModal = function(url, params) {
    $.get(url, params)
    .then(function(html) {
      $('#modal').html(html).modal('show');
      $('#modal .datepicker').datepicker({
        format: 'yyyy-mm-dd',
        orientation: 'auto',
        autoclose: true
      });
      $('#modal .time').timepicker({
        step: 15,
        timeFormat: 'H:i',
        maxTime: '23:59'
      });
      $('#modal').datepair();
    });
  };

The loaded modal has some input fields with the default date and time class names. The first time I open a modal, everything works as expected. But any subsequent open gives me Uncaught TypeError: Cannot set property 'minTime' of undefined.

Thoughts?

jonthornton commented 10 years ago

On my mobile right now, but best guess is that datepair isn't getting re-initialized the way you think it is, since #modal doesn't get re-created each time. Try attaching datepair to an element inside #modal.

uberllama commented 10 years ago

Will try, cheers.

uberllama commented 10 years ago

Victory!