EasyUI datetimebox control binding double click event to automatically select the current date and time

Time:2019-12-5

This method is to achieve this goal by extending the method without changing the original JS

First, expand a method of binding double click event in datetimebox control

$.extend($.fn.datetimebox.methods, {
     //Bind double click event method
     bindDblClick: function (jq) {
         var panel = $(jq).combo("panel");
         panel.find(".calendar-dtable tbody").unbind(".calendar").bind("dblclick.calendar", function (e) {
             var calendar = $(jq).datetimebox("calendar");
             var spinner = $(jq).datetimebox("spinner");
             var current = calendar.calendar("options").current;
 
             var year = current.getFullYear();
             var month = current.getMonth() + 1;
             var date = current.getDate();
             var time = spinner.spinner("getValue");
 
             var datetime = year + "-" + month + "-" + date + " " + time;
 
             $(jq).datetimebox("setValue", datetime);
 
             $(jq).combo("hidePanel");
         });
     }
 });

Then bind the double click event in the onshowpanel event in the datetimebox control

 $.extend($.fn.datetimebox.defaults, {
     onShowPanel: function () {
         $(this).datetimebox("bindDblClick");
     }
 });

Note: the above two extensions must be placed before the load datetimebox control.

This method is developed on the basis of easyui-1.7.0.