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

JQuery's trigger method doesn't populate currentTarget #1783

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

JQuery's trigger method doesn't populate currentTarget #1783

mgol opened this issue Oct 21, 2014 · 14 comments
Labels

Comments

@mgol
Copy link
Member

@mgol mgol commented Oct 21, 2014

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[0]; 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

@mgol

This comment has been minimized.

Copy link
Member Author

@mgol mgol commented Oct 21, 2014

Comment author: ArkadyKarev

Another words - jQuery not completely compatible with latest version of GWT - one of most popular Java frameworks for web apps, and probably with another libs.

@mgol mgol added this to the 3.0.0 milestone Oct 21, 2014
@mgol

This comment has been minimized.

Copy link
Member Author

@mgol mgol commented Oct 21, 2014

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.

@markelog markelog added the Core label Nov 2, 2014
@makfruit

This comment has been minimized.

Copy link

@makfruit makfruit commented Nov 10, 2014

Hi Guys,

Is there any ETA on this?

@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin commented Nov 11, 2014

It's marked for the next release which is a few months off. Would you like to take it? It's a pretty simple fix and would just need a relatively small addition as far as a unit test goes.

@makfruit

This comment has been minimized.

Copy link

@makfruit makfruit commented Nov 11, 2014

Thanks. I only want to track it =) Glad to know it's in your pipeline.

@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin commented Nov 25, 2014

@makfruit Can you take this jsbin and modify it to show that currentTarget isn't being set? I cannot reproduce the problem in a reduced test case.

@dmethvin dmethvin added the Needs info label Nov 25, 2014
@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin commented Dec 3, 2014

Without a test case we can't proceed on this. I can reopen if there is a test case showing the bug, but I was unable to create one using either simulated or user-generated events.

@HemantNegi

This comment has been minimized.

Copy link

@HemantNegi HemantNegi commented Mar 2, 2015

i think this replicates the problem can u guys have a look at it
http://jsfiddle.net/makfruit/C5QH3/

@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin commented Mar 2, 2015

That's a LOT of code. Can you modify http://jsbin.com/vaqasuweme/1/edit?html,output to demonstrate the problem? I couldn't find a situation where jQuery isn't already setting the target.

@markonikolic

This comment has been minimized.

Copy link

@markonikolic markonikolic commented Mar 4, 2015

Hi,

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:

  • if it is a jQuery handler, event.cureentTarget is present
  • if it is a native handler, there is no event.currentTarget.

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.

@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin commented Mar 4, 2015

Note that .onXXX properties are left over from the DOM0 days, the DOM Level 3 Events spec doesn't even mention them and I suspect currentTarget isn't set in the Event object because it wasn't originally defined for that case and they had back-compat concerns.

Here is an example with only native functions: http://jsfiddle.net/6s6r8ekm/8/

On Chrome 40 and Firefox 36, the currentTarget property is null whether it is fired inside native JavaScript or triggered via interaction with the control.

On Safari 8, the currentTarget property is undefined for both cases.

On IE11, the currentTarget property is null when fired by native JavaScript but populated as the <div> when triggered via interaction with the control.

So, 7 out of 8 native cases don't set currentTarget. Is there a reason jQuery should set the value in the event object passed to onchange if the browsers generally don't?

@markonikolic

This comment has been minimized.

Copy link

@markonikolic markonikolic commented Mar 5, 2015

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, currentTarget is properly populated. Tested with Chrome 40, Firefox 36 and IE 11, both triggering from code and interaction with the control populates currentTarget.

This seems a little bit strange, so I have tested firing native events from Chrome console in gwt application. Internally, gwt uses .onXXX properties for setting handlers and it works as expected. So, it seems to me that jQuery should populate currentTarget in case of native handlers.

I don't know if .onXXX properties are deprecated, if they are not, I beleive they should be covered as well.

@hunteke

This comment has been minimized.

Copy link

@hunteke hunteke commented Jun 7, 2016

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).

index.txt

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.

@dmethvin

This comment has been minimized.

Copy link
Member

@dmethvin dmethvin commented Jun 9, 2016

@hunteke your test uses inline handlers. That's why currentTarget isn't populated. As mentioned in gh-3146 inline handlers are a wontfix item.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants
You can’t perform that action at this time.