Autocomplete: Do not set value on multi-line input

This fixes an issue where contenteditable text was getting overwritten when
wrapping past the bottom or top of the autocomplete menu.

Fixes #9771
Closes gh-1184
This commit is contained in:
Yermo 2014-01-25 17:39:27 -05:00 committed by Scott González
parent ccb13240dd
commit 605a20ef06
2 changed files with 31 additions and 1 deletions

View File

@ -163,6 +163,32 @@ test( "allow form submit on enter when menu is not active", function() {
} }
})(); })();
asyncTest( "past end of menu in multiline autocomplete", function() {
expect( 2 );
var customVal = "custom value",
element = $( "#autocomplete-contenteditable" ).autocomplete({
delay: 0,
source: [ "javascript" ],
focus: function( event, ui ) {
equal( ui.item.value, "javascript", "Item gained focus" );
$( this ).text( customVal );
event.preventDefault();
}
});
element
.simulate( "focus" )
.autocomplete( "search", "ja" );
setTimeout(function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( element.text(), customVal );
start();
}, 50 );
});
asyncTest( "handle race condition", function() { asyncTest( "handle race condition", function() {
expect( 3 ); expect( 3 );
var count = 0, var count = 0,

View File

@ -545,7 +545,11 @@ $.widget( "ui.autocomplete", {
} }
if ( this.menu.isFirstItem() && /^previous/.test( direction ) || if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
this.menu.isLastItem() && /^next/.test( direction ) ) { this.menu.isLastItem() && /^next/.test( direction ) ) {
if ( !this.isMultiLine ) {
this._value( this.term ); this._value( this.term );
}
this.menu.blur(); this.menu.blur();
return; return;
} }