jQuery UI Datepicker weird behavior

最后都变了- 提交于 2019-12-05 13:57:50

It's a jQuery UI datepicker bug ticket it happens when the datepicker calculate and draw the months and doesn't use well the current month difference defined by showCurrentAtPos.

A possible solution is to add this block of code to the jquery.ui.datepicker.js file as reported in the ticket:

if (inst.drawMonth == showCurrentAtPos){

drawMonth = inst.drawMonth - showCurrentAtPos;

} else{

drawMonth = inst.drawMonth;

}

or to apply a patch in your onSelect function as you think:

onSelect: function (dateText, datePicker) {
    datePicker.drawMonth += $("#picker").datepicker("option", "showCurrentAtPos");
    $('#out').html(this.value);
}

Fiddle: http://jsfiddle.net/huPSb/1/

if you change select function with this code, everything will work fine

  onSelect: function (dateText, inst) {
         inst.drawMonth +=1; 
        $('#out').html(this.value);
    }

Here is working example http://jsfiddle.net/4FFnp/

I found a solution and patched the jquery-ui.js in basically two code lines in the datepicker subroutines _adjustDate() and _updateDatepicker():

--- jquery-ui.orig.js   2015-11-23 20:04:52.000000000 +0100
+++ jquery-ui.js    2015-11-23 17:56:37.987111191 +0100
@@ -8815,6 +8815,8 @@
        origyearshtml = inst.yearshtml = null;
        }, 0);
    }
+       // FIX BUG http://bugs.jqueryui.com/ticket/7288
+       inst.drawMonth += this._get(inst, "showCurrentAtPos");
},

// #6694 - don't focus the input if it's already focused
@@ -8940,9 +8942,14 @@
    if (this._isDisabledDatepicker(target[0])) {
        return;
    }
+       // FIX BUG http://bugs.jqueryui.com/ticket/7288
+       /*
        this._adjustInstDate(inst, offset +
        (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning
        period);
+       */
+       this._adjustInstDate(inst, offset, period);
+
    this._updateDatepicker(inst);
},

The bug fix has been submitted upstream in http://bugs.jqueryui.com/ticket/9923#comment:4 , http://bugs.jqueryui.com/ticket/7580?cnum_edit=5#comment:5 , http://bugs.jqueryui.com/ticket/7580#comment:5 )

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