From dec844570fae5edf56876b760b9358fde2ecb5e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 28 Nov 2012 10:33:44 -0500 Subject: [PATCH] Autocomplete: When appendTo is a jQuery object or a DOM element, don't search against the document. Fixes #8858 - Autocomplete: Fails when appendTo is detached from the DOM. --- tests/unit/autocomplete/autocomplete_options.js | 17 +++++++++++++++-- ui/jquery.ui.autocomplete.js | 10 +++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index 8331c53d5..d3a25d2fc 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -5,8 +5,9 @@ module( "autocomplete: options" ); var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ]; test( "appendTo", function() { - expect( 5 ); - var element = $( "#autocomplete" ).autocomplete(); + expect( 7 ); + var detached = $( "
" ), + element = $( "#autocomplete" ).autocomplete(); equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" ); element.autocomplete( "destroy" ); @@ -26,6 +27,18 @@ test( "appendTo", function() { element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" ); equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" ); element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: detached + }); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached jQuery object" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: detached[0] + }); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" ); + element.autocomplete( "destroy" ); }); function autoFocusTest( afValue, focusedLength ) { diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index f2a7089c4..5edb84d44 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -181,7 +181,7 @@ $.widget( "ui.autocomplete", { this._initSource(); this.menu = $( "