#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: |
Description
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, menu.select 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 follow-up: 2 Changed 12 years ago by
Milestone: | TBD → 1.9 |
---|---|
Priority: | minor → critical |
comment:2 Changed 12 years ago by
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
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:5 Changed 12 years ago by
Milestone: | 1.9 → 1.8.6 |
---|
comment:6 Changed 12 years ago by
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
Hi, today I faced this problem (IE8) with the two focus events. Problem (http://jsfiddle.net/vLq9E/16/):
- Page with one autocomplete textbox and list of radio one radio group
- Click any item from the list / selectmenu.
- 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 ) {
this._delay(function(){
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.
Works in Chome, Firefox, Opera, IE9b.
Broken in IE6-8.