Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Datepicker: reinitialize datepicker if mainDiv isn't on the page. Fix…
…ed #5679 - Datepicker should reinitialize if dpDiv is removed
  • Loading branch information
Roman Salnikov authored and mikesherov committed Nov 19, 2012
1 parent cf9fbce commit 7ffcaa2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/unit/datepicker/datepicker_core.js
Expand Up @@ -6,6 +6,16 @@

module("datepicker: core");

test("initialization - Reinitialization after body had been emptied.", function() {
expect( 1 );
var bodyContent = $('body').children(), inp = $("#inp");
$("#inp").datepicker();
$('body').empty().append(inp);
$("#inp").datepicker();
ok( $("#"+$.datepicker._mainDivId).length===1, "Datepicker container added" );
$('body').empty().append(bodyContent); // Returning to initial state for later tests
});

test( "widget method - empty collection", function() {
expect( 1 );
$( "#nonExist" ).datepicker(); // should create nothing
Expand Down
8 changes: 6 additions & 2 deletions ui/jquery.ui.datepicker.js
Expand Up @@ -2023,11 +2023,15 @@ $.fn.datepicker = function(options){

/* Initialise the date picker. */
if (!$.datepicker.initialized) {
$(document).mousedown($.datepicker._checkExternalClick).
find(document.body).append($.datepicker.dpDiv);
$(document).mousedown($.datepicker._checkExternalClick);
$.datepicker.initialized = true;
}

/* Append datepicker main container to body if not exist. */
if ($("#"+$.datepicker._mainDivId).length === 0) {
$('body').append($.datepicker.dpDiv);
}

var otherArgs = Array.prototype.slice.call(arguments, 1);
if (typeof options === 'string' && (options === 'isDisabled' || options === 'getDate' || options === 'widget')) {
return $.datepicker['_' + options + 'Datepicker'].
Expand Down

0 comments on commit 7ffcaa2

Please sign in to comment.