Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
JQuery's trigger method doesn't populate currentTarget #1783
Originally reported by ArkadyKarev at: http://bugs.jquery.com/ticket/15198
This problem (see subject) makes jQuery not completely compatible with some libs, which uses currentTarget.
For example following example will not work correctly: http://jsfiddle.net/makfruit/C5QH3/ go to "Vegetables > *Cucumber" and press "Activate next" button. It will perform only radio button changes, but attached handlers will not be triggered. If we will click radio buttons manually, we can see the changes in price and description, etc.
The following workaround will help: var event = jQuery.Event('change'); event.currentTarget = event.target = parent; parent.trigger(event); but anyway it seems like jQuerry bug.
Also I found the same requests in GWT groups. http://code.google.com/p/google-web-toolkit/issues/detail?id=8634
Issue reported for jQuery 2.1.1
Comment author: dmethvin
We can populate event.currentTarget but it also seems like this is a regression in GWT if it worked previously. So if GWT doesn't fix the regression on their end it won't be possible to use anything but the most recent version of jQuery with GWT.
I have found some more details on this issue and a small example that replicates the problem. The example can be found on http://jsfiddle.net/6s6r8ekm/5/ .
The issue is missing event.currentTarget when firing events from jQuery and handling event within GWT code - I don't know about other libraries. GWT expects event.currentTarget set, while jQuery sends different event object depending on the type of handler:
Example on jsfiddle demonstrates the problem without GWT. Both types of handlers can be tested and event data is dumped on browser console. Uncomment different handlers, click on 'Run' and observe browser console (changing combo box values does not correctly replicates the problem).
In jQuery code, you can check different behavior for different handler types in trigger function, search for comment 'Fire handlers on the event path'.
I am not so familiar with jQuery, so I don't know if this is by design or it is a bug.
Here is an example with only native functions: http://jsfiddle.net/6s6r8ekm/8/
On Chrome 40 and Firefox 36, the
On Safari 8, the
On IE11, the
So, 7 out of 8 native cases don't set
I agree with your findings on jsfiddle, however, I have copied the same example to http://jsbin.com/kirufetisu/1/edit?html,js,console,output - and the results are different,
This seems a little bit strange, so I have tested firing native events from Chrome console in gwt application. Internally, gwt uses
I don't know if
I don't know if this is still relevant to folks since 15 months ago, but we encountered this issue during a recent project, and I have a reduced test case (34 lines of HTML/JS, mostly boiler plate HTML and console.log to highlight the issue).
For reference to the dev who fixes the problem or nixes the bug report, I encountered this in the context of another bug report I just filed, so this file is the same as attached to #3146.