unable to bind event to datetimepicker plugin

狂风中的少年 提交于 2019-12-05 10:52:47

In datetimepicker's source, you can see author use an hack to disable closing when a date is selected. He calls it himself a bad hack.

Anyway, here is a workaround to able datepicker be closed when you double click on a date. I use onSelect function callback:

SEE DEMO

 $('#mydatepicker').datetimepicker({
     onSelect: function (e, t) {
         if (!t.clicks) t.clicks = 0;

         if (++t.clicks === 2) {
             t.inline = false;
             t.clicks = 0;
         }
         setTimeout(function () {
             t.clicks = 0
         }, 500);
     }
 });

So, in some way, i simulate dblclick behaviour using a timeout. I set it to 500ms but just play with this if you wish your dblclick to be more or less sensitive.

UPDATE

@JaredKnipp It appears that focus is set to input when month is switched (unvalid???), i don't have enough time to check it in detail, i'm sorry. As a simple workaround, you could try following snippet, add it to endDateTextBox onClose callback:

         var focusHandlers = $._data(endDateTextBox[0], "events").focus;
         $._data(endDateTextBox[0], "events").focus = {};
         endDateTextBox.one('focusin.datetimepicker mouseenter.datetimepicker', function () {
             setTimeout(function () {
                 $._data(endDateTextBox[0], "events").focus = focusHandlers;
                 endDateTextBox.blur();
             }, 0);
             $(this).off('focusin.datetimepicker mouseenter.datetimepicker');
         });

Note that if you are using jq version prior to 1.8, you have to use $.data() not $._data() Hope it helps...

Does the following work?

$('#ui-datepicker-div .ui-datepicker-calendar a').dblclick(function () {
  console.log('I just want to see if this event can be bound!');
});

dblclick docs.

Edit

try also live in jquery 1.7 or on in jquery 1.9 :

$('#ui-datepicker-div .ui-datepicker-calendar a').live('dblclick', function () {
  alert('I just want to see if this event can be bound!');
});

try to unbind a tag before binding it. maybe it bind with another function:

$('#ui-datepicker-div .ui-datepicker-calendar a').unbind('dblclick');
$('#ui-datepicker-div .ui-datepicker-calendar a').bind('dblclick', function () {
  alert('I just want to see if this event can be bound!');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!