2

I attach the datepicker to inputs in a global script file with like this:

$(document).on("focusin",".datePick", function () {
            $(this).datepicker({
                dateFormat: "dd/mm/yy",
                changeMonth: true,
                changeYear: true,
                onClose: function () { $(this).valid(); }
            });
        });

On a specific page, there are inputs(which will be used with datepicker) in a modal dialog(also jquery ui) and I call that page via $.load() and inject into a div in other page.

The code above works very well for static inputs in other pages but for the scenerio above, it shows the datepicker dialog fine but when I click on a date, it throws error(f is undefined)Edit: VS2010 throws "Unable to set value of the property 'currentDay': object is null or undefined"

Some people suggested to use live() method, but I dont want to use deprecated method.. What should I do about the issue?

Thanks in advance

Ozgu

4

3 回答 3

10

I experienced this exact error, and while my answer will not help the OP, maybe it will help others in the future.

I received this error message when I had an ID clash with another element in my page.

于 2012-08-03T10:10:34.287 回答
6

As mentioned in my comment on TJ VanToll's answer, as long as the parent element to which your trigger is bound is present at the time the DOM is loaded, you'll be fine.

See this fiddle for an example.

JS:

$(function(){
    $(document).on("focusin",".datePick", function () {
       $(this).datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            onClose: function () { $(this).valid(); }
        });
    });

    $('#focusin').append('<input class="datePick" name="datepicker" />');

});​

HTML:

<div id="focusin"></div>​

As long as your modal div is present on load, it should be able to capture your input after loading.

于 2012-07-10T15:43:38.873 回答
0

Using live, delegate, or on does not work with jQuery UI widgets because they are stateful plugins that must be instantiated after the necessary DOM nodes exist.

You can accomplish what you're looking for though by instantiating the datepicker after the additional markup has been injected. Here's an example doing so - http://jsfiddle.net/tj_vantoll/qN8dG/2/.

于 2012-07-10T15:32:45.717 回答