]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Don't update the value of the text field until after setting focus...
authorScott González <scott.gonzalez@gmail.com>
Mon, 19 Jul 2010 18:36:40 +0000 (14:36 -0400)
committerScott González <scott.gonzalez@gmail.com>
Mon, 19 Jul 2010 18:36:40 +0000 (14:36 -0400)
ui/jquery.ui.autocomplete.js

index 3f010c1f4c9af0c490ca8b383d04f059c883f017..c25a8884f266599add3ec564713ab978cbb44b02 100644 (file)
@@ -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)
@@ -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") ) {