Skip to content

Commit

Permalink
Autocomplete: Handle detached elements for appendTo after create.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed Dec 7, 2012
1 parent 1481b08 commit da17a23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tests/unit/autocomplete/autocomplete_options.js
Expand Up @@ -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 = $( "<div>" ),
element = $( "#autocomplete" ).autocomplete();
equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion ui/jquery.ui.autocomplete.js
Expand Up @@ -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();
Expand Down

0 comments on commit da17a23

Please sign in to comment.