Opened 12 years ago

Closed 12 years ago

Last modified 9 years ago

#6109 closed bug (fixed)

Autocomplete Change event does not fire in IE

Reported by: Kryal Owned by:
Priority: critical Milestone: 1.8.6
Component: ui.autocomplete Version: 1.8.5
Keywords: autocomplete change event mouse Cc:
Blocked by: Blocking:


When using the mouse to select an item in the autocomplete menu, a resulting 'change' event does not occur (only tested in IE). This is because the focus.autocomplete event fires twice after an item has been selected.

So first, fires:

Always true because menu was just clicked therefore, menu has focus and not the input field.
if ( self.element[0] !== doc.activeElement ) {

self.element.focus(); Fires focus.autocomplete which sets previous
self.previous = previous;
Re-sets previous value after focus event


Nothing wrong here, except that the focus event fires again. This time, the event comes from the browser and not jQuery. So:

Script focus: sets previous (user-typed value)
Following script: Re-set prevous (expected to end here)
Browser focus: sets previous (which is now the selected value)

Therefore, when the blur event fires on the input field the code thinks that the value hasn't changed, and doesn't trigger the change event.

Change History (7)

comment:1 Changed 12 years ago by Scott González

Milestone: TBD1.9
Priority: minorcritical

Works in Chome, Firefox, Opera, IE9b.

Broken in IE6-8.

comment:2 in reply to:  1 Changed 12 years ago by Scott González

Replying to scott.gonzalez:

Works in Chome, Firefox, Opera, IE9b.

It's actually broken in IE9b as well, not sure why I thought it was working there before

comment:3 Changed 12 years ago by Scott González

The problem is that when we trigger the focus event on selection, IE ends up triggering a native focus event asynchronously. Because the second event occurs asynchronously, our attempt to override the value of the previous property occurs too early.

comment:4 Changed 12 years ago by Scott González

Resolution: fixed
Status: newclosed

Fixed in 0ccc786.

comment:5 Changed 12 years ago by Scott González


comment:6 Changed 12 years ago by Scott González

Autocomplete: Handle IE firing focus events asynchronously. Fixes #6109 - Autocomplete Change event does not fire in IE.

Changeset: 0ccc78698b55d5e1bc336bb754b546a9ad19ea5c

comment:7 Changed 9 years ago by htalves

Hi, today I faced this problem (IE8) with the two focus events. Problem (

  1. Page with one autocomplete textbox and list of radio one radio group
  2. Click any item from the list / selectmenu.
  3. Immediately after that selection, click any radio option.

Listening to "change" event at autocomplete, sometimes, "change" was not triggered. That's due to the fact that "change", sometimes, is called before previous term is affected.

I solved it by adding "_delay" on autocomplete."_change" function, forcing it to be called later.

_change: function( event ) {


if ( this.previous !== this._value() ) {

this._trigger( "change", event, { item: this.selectedItem } );




I don't know if it was the best solution, just reporting for your better analysis, since it can be a little tricky to reproduce.

Note: See TracTickets for help on using tickets.