aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Heberden <danheberden@gmail.com>2011-02-15 10:15:46 -0800
committerScott González <scott.gonzalez@gmail.com>2011-02-15 13:27:18 -0500
commitab7a5b441aab8722429f8333bf8524fea4b00374 (patch)
treefca3de6c646d7378386db4498accc0d081550acc
parent685ac7a042536b005ab1cf8a59464d66bcc32cde (diff)
downloadjquery-ui-ab7a5b441aab8722429f8333bf8524fea4b00374.tar.gz
jquery-ui-ab7a5b441aab8722429f8333bf8524fea4b00374.zip
Datepicker: prevent datepicker initialization on empty jquery collection and add unit test. Fixed #6976 - datepicker creates extra dom element with empty object
(cherry picked from commit 5c3dc7d48ae501bd52476bfc45905130577d52c9)
-rw-r--r--tests/unit/datepicker/datepicker_core.js5
-rw-r--r--ui/jquery.ui.datepicker.js7
2 files changed, 11 insertions, 1 deletions
diff --git a/tests/unit/datepicker/datepicker_core.js b/tests/unit/datepicker/datepicker_core.js
index 9867022f7..2730ec861 100644
--- a/tests/unit/datepicker/datepicker_core.js
+++ b/tests/unit/datepicker/datepicker_core.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);
diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js
index 6c2e90795..ff6ebad52 100644
--- a/ui/jquery.ui.datepicker.js
+++ b/ui/jquery.ui.datepicker.js
@@ -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).