wvega / timepicker

A jQuery plugin to enhance standard form input fields helping users to select (or type) times
http://timepicker.co
GNU General Public License v2.0
216 stars 93 forks source link

Timepicker displays below bootstrap 3 modals #108

Open nickvellios opened 7 years ago

nickvellios commented 7 years ago

Using Bootstrap 3 with a timepicker inside of a modal, the timepicker is hidden behind the modal. Interestingly, changing the z-index didn't seem to fix it.

oliversteiner commented 7 years ago

Same Problem

oliversteiner commented 7 years ago

This workaround works for me

jQuery("input[type=time]").focus(function () {

  const $element = jQuery(this);

  // move timepicker-container from body to drupal modal
  const $bootstrap_modal_content = jQuery('.modal-content');
  const $timepicker_container = jQuery('.ui-timepicker-container');
  $timepicker_container.appendTo($bootstrap_modal_content);

  // get position top and left from active element
  var element_position = $element.position()

  // Get Height of  active Element
  var element_height = $element.outerHeight();

  // additional corrections
  var extra_height = 50;

  var new_top = element_position.top + element_height + extra_height;
  var new_left = element_position.left;

  $timepicker_container.css({
    'top'    : new_top,
    'left'   : new_left,
    'z-index': '10' // overlap other input elements
  });
});
gfdac commented 6 years ago

thanks oliversteiner... i used with $('#input-time)... and dont use the top and left.. worked flawless... thanks