Skip to content
Browse files

Autocomplete: Insert the live region before the input. Fixes #9172 - …

…Autocomplete: .replaceWith() fails to replace.
  • Loading branch information
scottgonzalez committed Mar 21, 2013
1 parent f281ce9 commit ff11b69a67e0176c851ff3bdec997c7a75d47a42
Showing with 11 additions and 1 deletion.
  1. +10 −0 tests/unit/autocomplete/autocomplete_core.js
  2. +1 −1 ui/jquery.ui.autocomplete.js
@@ -188,4 +188,14 @@ test( "ARIA", function() {
"Live region for multiple values" );

test( ".replaceWith() (#9172)", function() {
expect( 1 );

var element = $( "#autocomplete" ).autocomplete(),
replacement = "<div>test</div>",
parent = element.parent();
element.replaceWith( replacement );
equal( parent.html(), replacement );

}( jQuery ) );
@@ -296,7 +296,7 @@ $.widget( "ui.autocomplete", {
"aria-live": "polite"
.addClass( "ui-helper-hidden-accessible" )
.insertAfter( this.element );
.insertBefore( this.element );

// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete

2 comments on commit ff11b69


This comment has been minimized.

Copy link

@michalbcz michalbcz replied Jan 8, 2014

Why is this works? What is a reason that jQuery#replaceWith is sensitive on position of widget element (before vs after) ?


This comment has been minimized.

Copy link
Member Author

@scottgonzalez scottgonzalez replied Jan 8, 2014

When .replaceWith() runs, it removes the input element. When that element is removed, the autocomplete widget automatically destroys itself. When the autocomplete widget is destroyed, the live region is removed. When .replaceWith() does the insertion, it needs to have a reference to an element to insert relative to (it could be the next sibling, the previous sibling, or the parent if there are no siblings). We just have to use the position that happens to work with the current implementation. It's unlikely that the position used by .replaceWith() will change in the future.

Please sign in to comment.