From da17a232ca554254eabd3583805b381f6b525ec5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Fri, 7 Dec 2012 11:58:58 -0500 Subject: [PATCH] Autocomplete: Handle detached elements for appendTo after create. --- tests/unit/autocomplete/autocomplete_options.js | 6 +++++- ui/jquery.ui.autocomplete.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index d3a25d2fc..913f5bc28 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -5,7 +5,7 @@ module( "autocomplete: options" ); var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ]; test( "appendTo", function() { - expect( 7 ); + expect( 8 ); var detached = $( "
" ), element = $( "#autocomplete" ).autocomplete(); equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" ); @@ -39,6 +39,10 @@ test( "appendTo", function() { }); equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" ); element.autocomplete( "destroy" ); + + element.autocomplete().autocomplete( "option", "appendTo", detached ); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element via option()" ); + element.autocomplete( "destroy" ); }); function autoFocusTest( afValue, focusedLength ) { diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index c049b8569..a858b3382 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -314,7 +314,7 @@ $.widget( "ui.autocomplete", { this._initSource(); } if ( key === "appendTo" ) { - this.menu.element.appendTo( this.document.find( value || "body" )[0] ); + this.menu.element.appendTo( this._appendTo() ); } if ( key === "disabled" && value && this.xhr ) { this.xhr.abort(); -- 2.39.5