简体   繁体   English

jQuery UI Datepicker在AJAX调用中禁用

[英]jQuery UI Datepicker disabling at AJAX Call

I'm trying to disable an inline datepicker using the .datepicker('disable') method when the onChangeMonthYear callback function is fired. 我尝试在触发onChangeMonthYear回调函数时使用.datepicker('disable')方法禁用嵌入式.datepicker('disable')
This function makes an AJAX call (to fetch dates), and enables the datepicker back after success. 此函数进行AJAX调用(以获取日期),并在成功后启用日期选择器。

Unfortunately, the .datepicker('disable') never occurs ... 不幸的是.datepicker('disable')从未发生...

Apparently, after some deep digging with Firebug, the internal _disableDatepicker is called, but the class hasDatePicker is never found and thus the function returns early. 显然,在深入研究Firebug之后,将调用内部的_disableDatepicker ,但是从未找到类hasDatePicker ,因此该函数会提前返回。

I have encapsulate the callback functions in a global object, but this does not seems to affect the behavior of my code. 我已经将回调函数封装在一个全局对象中,但这似乎并不影响代码的行为。

onChangeMonthYear has a 3rd parameter, inst , that is supposed to refer to the datepicker element. onChangeMonthYear具有第三个参数inst ,它应该引用datepicker元素。 So I am supposed to access it through a $(inst) call. 因此,我应该通过$(inst)调用来访问它。

You will find the complete code on http://jsbin.com/ahano4/6/edit 您可以在http://jsbin.com/ahano4/6/edit上找到完整的代码

Here is your getEventsForDate function with some of the code removed. 这是您的getEventsForDate函数,其中删除了一些代码。

this.getEventsForDate = function(year, month, inst) {
    ...
    $(inst).datepicker('disable');
    ...
};

And here is your code that runs after the DOM has been loaded 这是在加载DOM之后运行的代码

$(function() {
    var date = new Date();
    Calendar.getEventsForDate(date.getFullYear(), date.getMonth()+1, {});
    ...
});

You are passing an empty object {} into the function as the third parameter and then calling the .datepicker() function on it. .datepicker()一个空对象{}作为第三个参数传递给该函数,然后在其上调用.datepicker()函数。 This clearly will not do anything useful. 显然,这将无济于事。

Don't you need to call the enable/disable by the actual element you're trying to affect? 您是否不需要通过要影响的实际元素来调用启用/禁用?

$(inst).datepicker('disable');//generic and not referring to anything in the DOM
should be
$('#calendar').datepicker('disable');//referring to the datepicker object in the DIV with the ID 'calendar'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM