Bug Tracker

Modify

Ticket #2481 (closed bug: fixed)

Opened 5 years ago

Last modified 15 months ago

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
Blocking: Blocked by:

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

comment:1 Changed 5 years ago by klaus

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

comment:2 Changed 5 years ago by klaus

  • Cc klaus added

comment:3 Changed 5 years ago by paul

  • Owner changed from paul to iMarc

comment:4 Changed 5 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 5 years ago by paul

  • Status changed from new to closed
  • Resolution set to fixed

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.