Bug 22135 - oninput doesn't work on divs
Summary: oninput doesn't work on divs
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-07 17:16 PST by Ojan Vafai
Modified: 2009-07-11 08:52 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ojan Vafai 2008-11-07 17:16:56 PST
The following HTML works in FF3 but not in webkit (as in, it alerts when you type in the input.

<div oninput=alert(1)><input></div>

On the otherhand, listening to input events on the div via addEventListener does work.
Comment 1 Alexey Proskuryakov 2008-11-08 01:46:13 PST
Confirmed with r38232.
Comment 2 Eric Seidel (no email) 2008-11-10 16:26:53 PST
According to HTML5, all of these on* are defined for all HTML elements:
http://www.whatwg.org/specs/web-apps/current-work/#event-handler-attributes

However, HTML5 does not mention "oninput" in its list.  We could pick on hixie to add it (or better yet, ask on the whatwg list).
Comment 3 Eric Seidel (no email) 2008-11-10 16:28:16 PST
To quote HTML5: "The following are the event handler attributes that must be supported by all HTML elements, as both content attributes and DOM attributes, and on Window objects, as DOM attributes:"
and then proceeds to list a bunch (not including oninput).
Comment 4 Michael A. Puls II 2009-06-12 06:48:33 PDT
For the input element, there's a table showing for what @type of input element fires 'input': <http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#the-input-element> (scroll down a bit to see the table)

input event:
<http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#event-input-input>

Under the textarea section, look for "fire a simple event called input"
<http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#the-textarea-element>

With that said, @oninput doesn't seem to be in the spec anywhere *yet*. But, I was under the assumption that 'input' should only work for text fields (and maybe other elements in contentEditable mode).

I had no idea that
<div oninput="alert(event.target)"><input></div>
and
<div><input oninput="alert(event.target)"></div>
did the exact same thing.

That's weird. But, it seems to work in Opera too.

It seems like this would complicate things though as doing:

<div oninput="alert(event.target)"><input><input><input><textarea></textarea></div>

would work like setting an 'input' capture listener.
Comment 5 Michael A. Puls II 2009-06-13 11:11:25 PDT
(In reply to comment #3)
> To quote HTML5: "The following are the event handler attributes that must be
> supported by all HTML elements, as both content attributes and DOM attributes,
> and on Window objects, as DOM attributes:"
> and then proceeds to list a bunch (not including oninput).
> 

Sorry, I guess it's just like you said. Works for the 'change' event too. You can do window.oniput = func, document.oninput = func and element.oninput = func (or use the addEventListener way or oninput= if the object is an element) and they'll be triggered by all descendants of that object that happen to fire 'input' (like input elements and textareas etc).

Only thing is, window.addEventListener('input' function(e){alert(e.currentTarget);}, false); will alert a window object in Firefox and a document object in Safari and Opera. That's for another bug though.
Comment 6 Erik Arvidsson 2009-06-19 10:28:49 PDT
I fixed this with http://trac.webkit.org/changeset/44811
Comment 7 Michael A. Puls II 2009-06-20 21:47:17 PDT
Yep. Works fine now in WebKit-r44837.
Comment 8 Alexey Proskuryakov 2009-06-21 01:10:29 PDT
Marking as fixed per the above.
Comment 9 Ian 'Hixie' Hickson 2009-07-10 15:45:29 PDT
oninput="" shouldn't work in the example given above, because the 'input' event doesn't bubble per spec.

Should I change the spec to make 'input' bubble? I'm pretty sure 'change' doesn't bubble either, though.
Comment 10 Ojan Vafai 2009-07-11 08:52:21 PDT
This bug was really about supporting it via addEventListener, but not via oninput. 

Filed Bug 27176 about bubbling oninput.