Bug Tracker

Opened 8 years ago

Closed 8 years ago

#14725 closed bug (notabug)

Event.data is proposed to be used for input events

Reported by: [email protected] Owned by: dmethvin
Priority: low Milestone: 1.11.1/2.1.1
Component: event Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


In the DOM3 event specification (http://www.w3.org/TR/DOM-Level-3-Events/#events-inputevents), beforeinput and input events have a data attribute. jQuery.event.fix sets the data attribute to whatever is passed in the on() handler.

While the data attribute is not yet implemented in any browsers, this is going to break when it happens. I have a text-input library and am trying to implement the input event correctly, but this breaks that.

Changing the jQuery data is likely impossible, but jQuery is used on more than half of all websites. Surely the jQuery foundation has some pull to change a future spec. Otherwise, using a guard like

if (event.originalEvent && handleObj.data === undefined){
  event.data = event.originalEvent.data;
  event.data = handleObj.data;

may help (with documentation that data passed in on() will overwrite the native data)

Change History (8)

comment:1 Changed 8 years ago by dmethvin

Status: newopen

There is already at least one existing event that passes an event.data I am pretty sure. This would be a good idea though.

comment:2 Changed 8 years ago by dmethvin

Component: unfiledevent
Milestone: None1.12/2.2
Owner: set to dmethvin
Priority: undecidedlow
Status: openassigned

comment:3 Changed 8 years ago by dmethvin

Milestone: 1.12/

comment:4 Changed 8 years ago by dmethvin

I've looked at this some more and think it's not the right direction.

We normalize a small subset of properties into the main event object passed to the handler. Right now the jQuery data is available consistently on event.data and the native data is always on event.originalEvent.data. This would make it more of a crapshoot as to what event.data represented which seems like a bad idea and even more confusing.

It's unfortunate that the standards group picked the same name as our existing property but there isn't much we can do about it now.

comment:5 Changed 8 years ago by [email protected]

I understand, though this fact should be documented.

As I mentioned, the best solution is political: the proposed standard should be changed to not break jQuery, especially since it has not been implemented yet. Does the jQuery foundation have any input in the W3C? You have a greater market share (and mind share) than any individual browser.

comment:6 Changed 8 years ago by dmethvin

That ship sailed long ago, the input event has been around for years but just not widely implemented. Really this is just like any other value that jQuery doesn't normalize, the best place to get it is event.originalEvent.

It's already documented:


comment:7 Changed 8 years ago by [email protected]

Good enough.

The documentation on the Event objecthttps://api.jquery.com/category/events/event-object/ actually explicitly says that the data field is copied (look under "Event Properties").

When I noted this, it took me an hour of digging through the source to figure out why it wasn't working, and even

$.event.fixHooks['input'] = { props:['data'] };

wouldn't work. That fact (that the data field is set after the event is normalized) ought to be explicitly noted in Event.datahttps://api.jquery.com/event.data/.

comment:8 Changed 8 years ago by dmethvin

Resolution: notabug
Status: assignedclosed
Note: See TracTickets for help on using tickets.