Navigation Menu

Skip to content

Commit

Permalink
Datepicker: prevent datepicker initialization on empty jquery collect…
Browse files Browse the repository at this point in the history
…ion and add unit test. Fixed #6976 - datepicker creates extra dom element with empty object

(cherry picked from commit 5c3dc7d)
  • Loading branch information
danheberden authored and scottgonzalez committed Feb 15, 2011
1 parent 685ac7a commit ab7a5b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/unit/datepicker/datepicker_core.js
Expand Up @@ -47,6 +47,11 @@ module("datepicker: core", {
}
});

test( "widget method - empty collection", function() {
$( "#nonExist" ).datepicker(); // should create nothing
ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" );
});

test("widget method", function() {
var actual = $("#inp").datepicker().datepicker("widget")[0];
same($("body > #ui-datepicker-div:last-child")[0], actual);
Expand Down
7 changes: 6 additions & 1 deletion ui/jquery.ui.datepicker.js
Expand Up @@ -1726,7 +1726,12 @@ function isArray(a) {
Object - settings for attaching new datepicker functionality
@return jQuery object */
$.fn.datepicker = function(options){


/* Verify an empty collection wasn't passed - Fixes #6976 */
if ( !this.length ) {
return this;
}

/* Initialise the date picker. */
if (!$.datepicker.initialized) {
$(document).mousedown($.datepicker._checkExternalClick).
Expand Down

0 comments on commit ab7a5b4

Please sign in to comment.