Ticket #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 | |
| 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: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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
