Datepicker in Popover Won't display

别来无恙 提交于 2020-01-02 03:11:15

问题


Using Twitter Bootstrap and the Bootstrap-datepicker extension. I'm not able to have a datepicker display inside a popover.

<a href="#" id="add-event-button" class="btn btn-small">Add an Event</a>

$(document).ready(function () {

    $("#add-event-button").popover({
        title: "Add an Event",
        placement: 'bottom',
        content: '<input class="datepicker" type="text" />',
        html: true
    }).click(function (e) {
        e.preventDefault();
    });
});

The popover displays just fine, and <input class="datepicker" type="text" /> outside of the popover context displays the datepicker fine. Any ideas?


回答1:


Try to extend the popover function with a callback, because datepicker cant be added to an non existing element on load, try this:

var tmp = $.fn.popover.Constructor.prototype.show;
$.fn.popover.Constructor.prototype.show = function () {
  tmp.call(this);
  if (this.options.callback) {
    this.options.callback();
  }
}

$("#add-event-button").popover({ 
  title: "Add an Event",
  placement: 'bottom',
  content: '<input class="datepicker" type="text" />',
  html: true, 
  callback: function() { 
    $('.datepicker').datepicker(); 
  }
}).click(function (e) {
  e.preventDefault();
});

Edit: Callback extension solution from here: Callback function after tooltip / popover is created with twitter bootstrap?



来源:https://stackoverflow.com/questions/15577417/datepicker-in-popover-wont-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!