Skip to content
Permalink
Browse files

Datepicker: prevent datepicker initialization on empty jquery collect…

…ion and add unit test. Fixed #6976 - datepicker creates extra dom element with empty object
  • Loading branch information
danheberden committed Feb 15, 2011
1 parent 6c3477e commit 5c3dc7d48ae501bd52476bfc45905130577d52c9
Showing with 11 additions and 1 deletion.
  1. +5 −0 tests/unit/datepicker/datepicker_core.js
  2. +6 −1 ui/jquery.ui.datepicker.js
@@ -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);
@@ -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).

0 comments on commit 5c3dc7d

Please sign in to comment.
You can’t perform that action at this time.