Side navigation
#7340 closed bug (fixed)
Opened October 28, 2010 06:06AM UTC
Closed March 21, 2011 02:53PM UTC
Last modified February 21, 2014 07:24AM UTC
.focus() not triggering focusin event for .live binding (1.4.3)?
| Reported by: | AP Erebus | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.5.2 |
| Component: | event | Version: | 1.4.3 |
| Keywords: | regression | Cc: | |
| Blocked by: | Blocking: |
Description
As demonstrated with this jsFiddle (http://jsfiddle.net/yt7Jd/2/), the focusin even isn't being triggered when .focus() is called.
This appears to be a bug introduced in 1.4.3 as when you change the jQuery version 1.4.2, it works correctly (as seen in this jsFiddle http://jsfiddle.net/yt7Jd/1/
I am testing on Chrome Stable 7.0.517.41
Attachments (0)
Change History (19)
Changed October 28, 2010 05:13PM UTC by comment:1
| component: | unfiled → event |
|---|---|
| keywords: | → regression |
| milestone: | 1.5 → 1.4.5 |
| priority: | undecided → blocker |
| status: | new → open |
Changed December 31, 2010 05:55PM UTC by comment:2
| owner: | → dmethvin |
|---|---|
| status: | open → assigned |
Changed January 02, 2011 04:09AM UTC by comment:3
It's this commit: https://github.com/dmethvin/jquery/commit/88068f82c199847d3679b130664dd91cc2e89f00
A focus from user action or DOM .focus() works fine, but a $().focus() is ignored. The test case seems to have intentionally used a DOM focus.
Changed January 17, 2011 06:50PM UTC by comment:4
| milestone: | 1.4.5 → 1.5 |
|---|
Changed January 19, 2011 04:38PM UTC by comment:6
RE: https://forum.jquery.com/topic/v1-4-3-unexpected-focus-behavior
even in 1.4.2, sequentially calling focus() on a,b,c is not exactly what the browsers do.
1.4.2:
1. focus a
2. focusin a
3. focus b
4. focusout a
5. focusin b
6. focus c
7. focusout b
8. focusin c
native (no jquery):
1. focus a
2. blur a
3. focus b
4. blur b
5. focus c
this is reproducible both manually (mouse/keyboard) and in code
i believe a proper mix should therefore be
$("#a").focus():
1. blur document.activeElement
2. focusout document.activeElement (bubbles)
3. change document.activeElement (if there was a change)
4. haschanged document.activeElement (maybe a new bubbling change event)
5. focus a
6. focusin a (bubbles)
$("#b").focus():
repeat above
$("#c").focus():
repeat above
this is all logged using $('input').bind('focus blur focusin focusout'), not live() or delegate.
blur() should also work via 1-4. i know that different browsers fire change events before or after blur events, so the change() order might be screwy, but a custom "haschanged" or "changed" should always fire reliably after focusout().
just random thoughts of course,
Leon
Changed January 21, 2011 02:25PM UTC by comment:7
I've reverted the commit in question here:
https://github.com/jquery/jquery/commit/328a86f9a0d3f0907cc950f7543e34cb3efbda3f
Changed January 21, 2011 05:10PM UTC by comment:8
i'm not too familiar with the details of the event dispatcher in jquery. i only know the high level overview of what's done (uniformize events via fix(), live handlers for blur/focus/change done via capture, then focusin/out triggered on e.target)
i'll try to slap a patch together that fires off events in the way i've outlined. also noticed there's a .specialChange there already, will need to dig further. preferably, i'd like to get something consistent into 1.5 final since changes to event dispatch order can be chalked up to a major version bump.
are there any IRC logs relating to discussions of event flow that i can read through instead of trying to make sense of everything through code analysis?
thanks,
leon
Changed January 22, 2011 03:31AM UTC by comment:9
| blockedby: | → 8036 |
|---|
Changed January 24, 2011 05:10PM UTC by comment:10
| milestone: | 1.5 → 1.6 |
|---|
Pushing to 1.6.
Changed January 25, 2011 07:15AM UTC by comment:11
might as well add this in here, hacked together some jquery-less event delegation code that has consistent event order (no IE)
yes, there are numerous issues, just proto. technically if you want to catch focusin/out without delegating a blur/focus at same time...those first-order handlers should be registered capturing on document implicitly during lib init. (i think jq does this already)
leon
Changed February 14, 2011 11:12PM UTC by comment:12
| blocking: | → 8275 |
|---|
(In #8275) Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!
jQuery 1.4.4 contained some code to make focusin/focusout bubble also in non IE-browsers. But the code was buggy and got removed for 1.5 .
You can follow the ticket #7340 for progress on this issue.
In the meantime you should be able to workaround this problem by binding to the focus event instead of focusin.
Changed February 28, 2011 05:42PM UTC by comment:13
| milestone: | 1.6 → 1.5.2 |
|---|
Changed March 07, 2011 05:08PM UTC by comment:14
Changed March 21, 2011 02:53PM UTC by comment:15
| resolution: | → fixed |
|---|---|
| status: | assigned → closed |
Landed.
Changed March 24, 2011 03:22PM UTC by comment:16
#8582 is a duplicate of this ticket.
Changed April 21, 2011 06:33PM UTC by comment:17
Hi,
I have some issues with trigger('focus') firing twice as of 1.5.2, 1.6beta, and the git version. Here is an example: http://jsfiddle.net/WVcy5/
In this example, I binded 'focus' and 'focusin' to an object and simply trigger('focus') on it.
expected output:
Focus called, count is :1 Do nothing
actual output:
Focus called, count is :1 Do nothing Focus called, count is :2
It seems like trigger('focus') would cause "focus" to fire twice if "focusin" is also binded, is this expected behavior?
Thanks,
Harris
Changed April 29, 2011 04:14PM UTC by comment:18
In addition to my previous post, it seems like it's only a problem when "tabindex" is in the element. I tried it on 1.6rc1 and the problem remains.
To demonstrate, you can checkout my github unit test here:
Or you can try this example here:
Thanks,
Harris
Changed February 21, 2014 07:24AM UTC by comment:19
Interesting to see ... thank you it's well done :)[http://www.aquademica.se/mogel/fuktskada/ fuktskada]