Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triggering focus event with namespace runs all focus listeners #1750

Closed
mgol opened this issue Oct 21, 2014 · 5 comments
Closed

triggering focus event with namespace runs all focus listeners #1750

mgol opened this issue Oct 21, 2014 · 5 comments
Assignees
Labels
Milestone

Comments

@mgol
Copy link
Member

mgol commented Oct 21, 2014

Originally reported by peter@… at: http://bugs.jquery.com/ticket/14359

Using jQuery 1.9 onwards, calling .trigger('focus.myevent') focusses the target element and triggers all "focus" handlers, regardless of namespace.

This is inconsistent with other events, where only handlers with the "myevent" namespace would be triggered.

 http://jsfiddle.net/PeterChaplin/GUSN5/

This behaviour does not appear to be present in 1.7.2 or 1.8.3.

I have only tested this on Google Chrome Version 29.0.1547.66 m, in Windows 7

Issue reported for jQuery 1.10.2

@mgol
Copy link
Member Author

mgol commented Oct 21, 2014

Comment author: dmethvin

This is another result of triggering the native focus event so we can get the event order right. There are no jQuery extensions (namespaces, data) in those cases. See #13428.

@mgol
Copy link
Member Author

mgol commented Oct 21, 2014

Comment author: gibson042

Third time's the charm...  https://github.com/jquery/jquery/pull/1367

@mgol mgol added the Bug label Oct 21, 2014
@timmywil
Copy link
Member

Related: #1735

@caseyjhol
Copy link

This might be an acceptable workaround to prevent firing the handler twice as mentioned in #1741 (comment):

var $x = $("#aninput");
$x.triggerHandler("focus.myevent", ['extra', 'data']);
$x[0].focus();

$x.on("focus.myevent", function (e, extra, data) {
    if (e.originalEvent) return;
    console.log(extra, data);
});

$x.on("focus.notfired", function (e, extra, data) {
    if (e.originalEvent) return;
    console.log("This won't be fired.");
});

@gibson042 gibson042 modified the milestones: 4.0.0, 3.4.0 Apr 9, 2019
@gibson042
Copy link
Member

Fixed by 669f720: http://jsfiddle.net/3nwhq0o7/1/

@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants