Skip to content

Commit 5c3dc7d

Browse files
committed
Datepicker: prevent datepicker initialization on empty jquery collection and add unit test. Fixed #6976 - datepicker creates extra dom element with empty object
1 parent 6c3477e commit 5c3dc7d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tests/unit/datepicker/datepicker_core.js

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ module("datepicker: core", {
4747
}
4848
});
4949

50+
test( "widget method - empty collection", function() {
51+
$( "#nonExist" ).datepicker(); // should create nothing
52+
ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" );
53+
});
54+
5055
test("widget method", function() {
5156
var actual = $("#inp").datepicker().datepicker("widget")[0];
5257
same($("body > #ui-datepicker-div:last-child")[0], actual);

ui/jquery.ui.datepicker.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,12 @@ function isArray(a) {
17261726
Object - settings for attaching new datepicker functionality
17271727
@return jQuery object */
17281728
$.fn.datepicker = function(options){
1729-
1729+
1730+
/* Verify an empty collection wasn't passed - Fixes #6976 */
1731+
if ( !this.length ) {
1732+
return this;
1733+
}
1734+
17301735
/* Initialise the date picker. */
17311736
if (!$.datepicker.initialized) {
17321737
$(document).mousedown($.datepicker._checkExternalClick).

0 commit comments

Comments
 (0)