mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
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.
This commit is contained in:
parent
e77edc6099
commit
dec844570f
@ -5,8 +5,9 @@ module( "autocomplete: options" );
|
|||||||
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ];
|
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ];
|
||||||
|
|
||||||
test( "appendTo", function() {
|
test( "appendTo", function() {
|
||||||
expect( 5 );
|
expect( 7 );
|
||||||
var element = $( "#autocomplete" ).autocomplete();
|
var detached = $( "<div>" ),
|
||||||
|
element = $( "#autocomplete" ).autocomplete();
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
|
equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
@ -26,6 +27,18 @@ test( "appendTo", function() {
|
|||||||
element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
|
element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
|
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
|
||||||
element.autocomplete( "destroy" );
|
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 ) {
|
function autoFocusTest( afValue, focusedLength ) {
|
||||||
|
10
ui/jquery.ui.autocomplete.js
vendored
10
ui/jquery.ui.autocomplete.js
vendored
@ -181,7 +181,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
this._initSource();
|
this._initSource();
|
||||||
this.menu = $( "<ul>" )
|
this.menu = $( "<ul>" )
|
||||||
.addClass( "ui-autocomplete" )
|
.addClass( "ui-autocomplete" )
|
||||||
.appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] )
|
.appendTo( this._appendTo() )
|
||||||
.menu({
|
.menu({
|
||||||
// custom key handling for now
|
// custom key handling for now
|
||||||
input: $(),
|
input: $(),
|
||||||
@ -320,6 +320,14 @@ $.widget( "ui.autocomplete", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_appendTo: function() {
|
||||||
|
var element = this.options.appendTo;
|
||||||
|
if ( element && (element.jquery || element.nodeType) ) {
|
||||||
|
return $( element );
|
||||||
|
}
|
||||||
|
return this.document.find( element || "body" ).eq( 0 );
|
||||||
|
},
|
||||||
|
|
||||||
_isMultiLine: function() {
|
_isMultiLine: function() {
|
||||||
// Textareas are always multi-line
|
// Textareas are always multi-line
|
||||||
if ( this.element.is( "textarea" ) ) {
|
if ( this.element.is( "textarea" ) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user