]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Support changing the `appendTo` option after init
authorTJ VanToll <tj.vantoll@gmail.com>
Fri, 15 Nov 2013 13:42:20 +0000 (08:42 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 29 Jan 2015 22:47:47 +0000 (17:47 -0500)
tests/unit/datepicker/datepicker_options.js
ui/datepicker.js

index fedfe7dd5ed3381ed60bf29dff17ae288094be94..72f459db0dc04591b03060de450303b5828c4a16 100644 (file)
@@ -2,6 +2,44 @@
 
 module( "datepicker: options" );
 
+test( "appendTo", function() {
+       expect( 6 );
+       var container,
+               detached = $( "<div>" ),
+               input = $( "#datepicker" );
+
+       input.datepicker();
+       container = input.datepicker( "widget" ).parent()[ 0 ];
+       equal( container, document.body, "defaults to body" );
+       input.datepicker( "destroy" );
+
+       input.datepicker({ appendTo: "#qunit-fixture" });
+       container = input.datepicker( "widget" ).parent()[ 0 ];
+       equal( container, $( "#qunit-fixture" )[ 0 ], "child of specified element" );
+       input.datepicker( "destroy" );
+
+       input.datepicker({ appendTo: "#does-not-exist" });
+       container = input.datepicker( "widget" ).parent()[ 0 ];
+       equal( container, document.body, "set to body if element does not exist" );
+       input.datepicker( "destroy" );
+
+       input.datepicker()
+               .datepicker( "option", "appendTo", "#qunit-fixture" );
+       container = input.datepicker( "widget" ).parent()[ 0 ];
+       equal( container, $( "#qunit-fixture" )[ 0 ], "modified after init" );
+       input.datepicker( "destroy" );
+
+       input.datepicker({ appendTo: detached });
+       container = input.datepicker( "widget" ).parent()[ 0 ];
+       equal( container, detached[ 0 ], "detached jQuery object" );
+       input.datepicker( "destroy" );
+
+       input.datepicker({ appendTo: detached[ 0 ] });
+       container = input.datepicker( "widget" ).parent()[ 0 ];
+       equal( container, detached[ 0 ], "detached DOM element" );
+       input.datepicker( "destroy" );
+});
+
 test( "dateFormat", function() {
        expect( 0 );
 });
index 55b6c0f74ac2190a512f11203e890b663f9f77a1..28fd9191a1b83327ff5c4022d23e128b2ab056f5 100644 (file)
@@ -618,6 +618,13 @@ $.widget( "ui.datepicker", {
        },
        widget: function() {
                return this.picker;
+       },
+       _setOption: function( key, value ) {
+               this._super( key, value );
+
+               if ( key === "appendTo" ) {
+                       this.picker.appendTo( this._appendTo() );
+               }
        }
 });