Skip to main content

Bug Tracker

Side navigation

#13428 closed bug (migrated)

Opened February 10, 2013 07:53PM UTC

Closed October 21, 2014 12:11AM UTC

focus event ignores additional data when triggered

Reported by: mail@heiko-salmon.de Owned by: mail@heiko-salmon.de
Priority: low Milestone: None
Component: event Version: 1.9.1
Keywords: Cc: dmethvin
Blocked by: Blocking:
Description

http://fiddle.jshell.net/rvX5Y/4/

$('input').on('focus', function(event, extra, data) {
    console.log(extra, data);
});
$('input').trigger('focus', ['extra', 'data']);

Works in version 1.8.3.

Does not work in version 1.9.0 and 1.9.1.

Expected behavior: Console shows "extra data"

False Behavior: Console shows "undefined undefined"

Browser: Firefox 18,

OS: OS X 10.8.2

Attachments (0)
Change History (17)

Changed February 10, 2013 09:38PM UTC by gibson042 comment:1

blockedby: → 13353
cc: → dmethvin
component: unfiledevent

This is exactly analogous to #13353... I'm starting to think we should generalize and incorporate that solution after all.

Changed February 10, 2013 10:18PM UTC by dmethvin comment:2

Way too much code though. I was thinking that if the user passed data that we use the "standard" trigger path rather than native events. It passes the data at the expense of some non-standard event behavior, but I think people are probably misusing the event system most of the time when this happens.

Changed February 11, 2013 01:51AM UTC by gibson042 comment:3

That'd probably be acceptable for focus, but click handlers would see different checked states on checkbox and radio inputs when the event was provided trigger data—a ''definite'' no-go.

Changed February 12, 2013 04:05AM UTC by dmethvin comment:4

owner: → mail@heiko-salmon.de
status: newpending

So, to the OP, are you using this to initialize on page load? Could you use .triggerHandler() instead, or are you really trying to focus the element as well?

Changed February 12, 2013 03:21PM UTC by mail@heiko-salmon.de comment:5

status: pendingnew

I was trying to distinguish between a) clicking or tabbing into the input field and b) using the .trigger('focus') function somewhere else. Nothing on page load.

Changed March 10, 2013 11:53PM UTC by dmethvin comment:6

#13590 is a duplicate of this ticket.

Changed March 13, 2013 01:25AM UTC by timmywil comment:7

status: newopen
version: git1.9.1

Changed April 02, 2013 05:05PM UTC by dmethvin comment:8

#13711 is a duplicate of this ticket.

Changed April 10, 2013 12:24PM UTC by anonymous comment:9

triggerHandler is not really an acceptable workaround since it won't actually focus, blur, etc...

Changed April 10, 2013 12:28PM UTC by dmethvin comment:10

It is a fine workaround. Just do the indicated DOM action afterwards.

var $x = $("#aninput");
$x.triggerHandler("focus");
$x[0].focus();

Changed April 10, 2013 12:38PM UTC by anonymous comment:11

People from the core team certainly know this already, but this arises from:

focus: {
  // Fire native event if possible so blur/focus sequence is correct
  trigger: function() {
    if ( this !== safeActiveElement() && this.focus ) {
      this.focus();

and

blur: {
  trigger: function() {
  if ( this === safeActiveElement() && this.blur ) {
    this.blur();

Changed April 10, 2013 12:44PM UTC by anonymous comment:12

Won't this trigger the handlers twice?

Replying to [comment:10 dmethvin]:

It is a fine workaround. Just do the indicated DOM action afterwards.
> var $x = $("#aninput");
> $x.triggerHandler("focus");
> $x[0].focus();
> 

Changed July 04, 2013 12:05PM UTC by osmestad comment:13

_comment0: I also have this issue and it is still valid with latest 1.x and 2.x, here is a jsFiddle for what I'm doing: \ http://jsfiddle.net/2dVMa/ \ \ My problem with using triggerHandler is that I am trying to avoid running the code in my 'focus' handler when setting focus programatically (with 'trigger'). \ \ Others with same issue: http://forum.jquery.com/topic/extra-arguments-passed-to-trigger-doesn-t-reach-blur-event-handler-when-element-has-focus \ \ Browser: Chrome 27, OS: OS X 10.8.4 \ 1372939715312302

I also have this issue and it is still valid with latest 1.x and 2.x, here is a jsFiddle for what I'm doing:

http://jsfiddle.net/2dVMa/

My problem with using triggerHandler is that I am trying to avoid running the code in my 'focus' handler when setting focus programatically (with 'trigger').

(Only workarounds I can think of would be unbinding, triggering focus and then rebinding, or reverting to 1.8... )

Others with same issue: http://forum.jquery.com/topic/extra-arguments-passed-to-trigger-doesn-t-reach-blur-event-handler-when-element-has-focus

Browser: Chrome 27, OS: OS X 10.8.4

Changed January 04, 2014 08:14PM UTC by dmethvin comment:14

#14658 is a duplicate of this ticket.

Changed February 24, 2014 01:37PM UTC by dmethvin comment:15

#14829 is a duplicate of this ticket.

Changed October 06, 2014 09:12PM UTC by m_gol comment:16

priority: undecidedlow

Changed October 21, 2014 12:11AM UTC by m_gol comment:17

resolution: → migrated
status: openclosed