Skip to content

Commit

Permalink
Autocomplete: Don't update the value of the text field until after se…
Browse files Browse the repository at this point in the history
…tting focus. Fixes #5639 - Cursor jumps to beginning on select.
  • Loading branch information
scottgonzalez committed Jul 19, 2010
1 parent 5e3755a commit 53489b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -132,9 +132,12 @@ $.widget( "ui.autocomplete", {
}
},
selected: function( event, ui ) {
var item = ui.item.data( "item.autocomplete" );
var item = ui.item.data( "item.autocomplete" ),
setValue = false;
if ( false !== self._trigger( "select", event, { item: item } ) ) {
self.element.val( item.value );
// #5639 - if we set the value before setting focus
// the cursor will move to the beginning of the field in IE
setValue = true;
}
self.close( event );
// only trigger when focus was lost (click on menu)
Expand All @@ -144,6 +147,9 @@ $.widget( "ui.autocomplete", {
self.previous = previous;
}
self.selectedItem = item;
if ( setValue ) {
self.element.val( item.value );
}
},
blur: function( event, ui ) {
if ( self.menu.element.is(":visible") ) {
Expand Down

0 comments on commit 53489b5

Please sign in to comment.