#8148 closed bug (fixed)
Change event is never triggered if another element is programmatically focused
Reported by: | scottgonzalez | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.next |
Component: | event | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description (last modified by )
If the value of a text field is changed and then focus is programmatically moved to another element, the native change event is triggered, but any event handlers bound via jQuery will not be triggered.
Change History (7)
comment:1 Changed 13 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 13 years ago by
Component: | unfiled → event |
---|---|
Keywords: | needsreview added |
Scott, I'm adding this to show that change is fired when the input receives focus again:
comment:3 follow-up: 5 Changed 13 years ago by
OK, here's a bare-DOM example showing the order events are fired:
http://jsbin.com/elazu4/8/edit
I think what is happening here is jQuery.event.trigger sets a jQuery.event.triggered flag just before calling the native DOM <a>.focus() method. The browser fires the blur and change events DURING that process, which normally would be handled but are blocked because the flag is checked in eventHandle:
https://github.com/jquery/jquery/blob/master/src/event.js#L402
https://github.com/jquery/jquery/blob/master/src/event.js#L85
It works properly if you start the process by using DOM <a>.focus() which calls the jQuery.event.handle directly, rather than $("a").focus() which calls jQuery.event.trigger. This appears to have been the way events were handled for several years afaict.
comment:5 Changed 13 years ago by
Replying to dmethvin:
It works properly if you start the process by using DOM <a>.focus() which calls the jQuery.event.handle directly, rather than $("a").focus() which calls jQuery.event.trigger. This appears to have been the way events were handled for several years afaict.
The exact same issue can be seen by using .blur()
on the node itself rather than .focus()
on an other node: $(this).blur()
will fail to trigger onchange()
but this.blur()
will correctly trigger it.
comment:7 Changed 12 years ago by
Keywords: | needsreview removed |
---|
This is the cause of http://bugs.jqueryui.com/ticket/6918