]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: prevent datepicker initialization on empty jquery collection and add...
authorDan Heberden <danheberden@gmail.com>
Tue, 15 Feb 2011 18:15:46 +0000 (10:15 -0800)
committerScott González <scott.gonzalez@gmail.com>
Tue, 15 Feb 2011 18:27:18 +0000 (13:27 -0500)
(cherry picked from commit 5c3dc7d48ae501bd52476bfc45905130577d52c9)

tests/unit/datepicker/datepicker_core.js
ui/jquery.ui.datepicker.js

index 9867022f7100a246bf470d66215382e51cf72599..2730ec86124846e20a5712c8b2633c31949e4527 100644 (file)
@@ -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);
index 6c2e90795cc4633661ea91f9a0a6efe67a02839a..ff6ebad522c558329ec69670d4fe83d0caa76f6b 100644 (file)
@@ -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).