Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 8 years ago

#2481 closed bug (fixed)

Inflexibility with UI Datepicker: still limited to ready event with bottom script approach

Reported by: klaus Owned by: iMarc
Priority: minor Milestone: 1.2.4
Component: ui Version: 1.2.3
Keywords: Cc: klaus
Blocked by: Blocking:

Description

Due to the usage of the document ready event

/* Initialise the date picker. */
$(document).ready(function() {
    $.datepicker = new Datepicker(); // singleton instance
    $(document.body).append($.datepicker._datepickerDiv).
        mousedown($.datepicker._checkExternalClick);
});

the datepicker becomes inflexible in its usage. Using a bottom script approach (instead of DOM ready) still requires the ready event to initialize a datepicker on the page to prevent an error ($.datepicker has no properties).

Quickfixed it by moving the datepicker initialization into the datepicker method itself, although I may have overlooked the impact of this:

$.fn.datepicker = function(options){

    /* Initialise the date picker if necessary. */
    if (!$.datepicker) {
        $.datepicker = new Datepicker(); // singleton instance
        $(document.body).append($.datepicker._datepickerDiv).
            mousedown($.datepicker._checkExternalClick);
    }

    var otherArgs = Array.prototype.slice.call(arguments, 1);
    ...
};

Change History (5)

comment:1 Changed 12 years ago by klaus

Summary: Inflexibility with UI Datepicker: limited to window load event with bottom script approachInflexibility with UI Datepicker: still limited to ready event with bottom script approach

comment:2 Changed 12 years ago by klaus

Cc: klaus added

comment:3 Changed 12 years ago by paul

Owner: changed from paul to iMarc

comment:4 Changed 12 years ago by DanSwitzer2

@Mark:

Klaus' recommend fix also resolves the issue I was having trying to use the $.datepicker() inside a div which has it's content loaded via AJAX. When the document.ready() method is used, errors are thrown. By initializing on first call, all issues are resolved.

-Dan

comment:5 Changed 12 years ago by paul

Resolution: fixed
Status: newclosed

I think his should be fixed by moving the instance creation to the block before document.ready.

Note: See TracTickets for help on using tickets.