This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 11129 - Remove forminput, formchange and related dispatch methods
Summary: Remove forminput, formchange and related dispatch methods
Status: CLOSED FIXED
Alias: None
Product: HTML WG
Classification: Unclassified
Component: LC1 HTML5 spec (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-23 00:00 UTC by Erik Arvidsson
Modified: 2011-08-04 05:06 UTC (History)
10 users (show)

See Also:


Attachments
testcase without forminput or formchange (2.60 KB, text/html)
2011-01-24 12:45 UTC, Olli Pettay
Details
testcase (2.59 KB, text/html)
2011-01-24 12:49 UTC, Olli Pettay
Details
testcase 2 (1.98 KB, text/html)
2011-01-24 15:11 UTC, Mounir Lamouri
Details

Comment 1 Rob Crowther 2010-11-24 02:59:26 UTC
I'm not sure I get the 'increasing the size of the API' argument, can someone expand on it?

To pick a some examples for comparison: Is it worth increasing the size of the API to have valueAsNumber or valueAsDate when both can be easily worked around by the developer if required?  Is it worth adding an output element when we could just have a span and use innerHTML?

Why is this case less worthy than either of those two examples?

I like that an onforminput attribute can be added to the output element.  Even if that isn't really best practice it's simple for beginners to grasp, and it keeps all the logic for each output element in one place (and makes the output element much easier to explain).
Comment 2 Ian 'Hixie' Hickson 2011-01-01 06:10:57 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Rejected
Change Description: no spec change
Rationale: Since you can't register capturing handlers declaratively, and since form controls can be all over the place in the DOM now, I think 'forminput' and 'formchange' are still very helpful and have clear use cases. As as straightforward demonstration of this, try to rewrite the examples in the spec that use these features to do them without onforminput/onformchange and see whether it's still as simple.
Comment 3 Olli Pettay 2011-01-24 12:45:02 UTC
Created attachment 945 [details]
testcase without forminput or formchange

I found 3 examples in the spec and all those can be trivially
handled without these additional events.
Comment 4 Olli Pettay 2011-01-24 12:49:40 UTC
Created attachment 946 [details]
testcase

Oops, I left some unrelated alert() in the previous file.
(I was just testing form element's scoping there..)
Comment 5 Mounir Lamouri 2011-01-24 12:52:47 UTC
I'm reopening the bug because, like Olli, I do think forminput and formchange are not needed.
Comment 6 Olli Pettay 2011-01-24 13:07:05 UTC
One problem with forminput/formchange -like broadcasting events is that
what should happen when one of the targets is moved to another form
or even another document when some other target for the events is
handling the event. Well, perhaps nothing special shouldn't happen,
but it would be rather strange to get forminput when the element is in a
form which has never been used yet.

In fact, that sort of breaks the algorithm's step 3
"For each element in controls, in tree order, fire a simple event named event
name at the element."
Depending on how you read that, tree order should be checked either just
once before firing any events, or before each event.
Comment 7 Rob Crowther 2011-01-24 14:38:10 UTC
> all those can be trivially handled without these additional events

What does your definition of 'trivially handled' encompass?  Here's the amount of JavaScript required in the spec examples purely in terms of character counts (not including spaces):

calculator: 67 characters
password validity: 37 characters
car price: 15 characters

Plus, slightly more meta, understanding of event bubbling required: false.

With your examples:

calculator: 200 characters
password validity: 185 characters
car price: 116 characters

Understanding event bubbling required: true.

I don't agree that you can so easily characterize a minimum of 300% more code and the requirement to understand event bubbling as trivial.

> I do think forminput and formchange are not needed

As I previously asked, why is this not needed, but valueAsNumber is?
Comment 8 Olli Pettay 2011-01-24 15:10:00 UTC
(In reply to comment #7) 
You count things strangely. For example in the original car example there is
over 350 characters javascript.


> Understanding event bubbling required: true.
?
I just happened to use addEventListener on document element using
bubble phase. That is not the point.

 
> As I previously asked, why is this not needed, but valueAsNumber is?
This bug is not about valueAsNumber.
I'm personally not at all sure why that is needed.
parseFloat(value) and valueAsNumber are not that different.
Comment 9 Mounir Lamouri 2011-01-24 15:11:11 UTC
Created attachment 947 [details]
testcase 2

With this file, there should be no overhead...
Comment 10 Simon Pieters 2011-01-26 10:16:54 UTC
I think we should keep these events and the dispatch APIs. They're exist for convenience, and they are convenient. They're hardly an implementation burden. (Event handler attributes in general are also for convenience but are redundant with addEventListener.)
Comment 11 Olli Pettay 2011-01-26 11:23:00 UTC
But what is the use case for the events and the related methods?
Comment 12 Olli Pettay 2011-01-26 11:23:37 UTC
I mean use case which can't be trivially done with the existing events.
Comment 13 Simon Pieters 2011-01-26 12:21:56 UTC
Use case is updating something when one out of many form controls are changed, using just one declarative event listener. Use case for dispatching the event is causing that event listener to run after some script has changed stuff, maybe initially when loading the page.
Comment 14 Olli Pettay 2011-01-26 13:21:19 UTC
Those are not really a use cases, but descriptions how one could
use the events and methods ;)
Also, why couldn't scripts use the existing events for the first case?
And for the latter one there could be just a javascript function to call.
Comment 15 Simon Pieters 2011-01-26 21:41:21 UTC
(In reply to comment #14)
> Those are not really a use cases, but descriptions how one could
> use the events and methods ;)

Consider a shopping cart where the customer can select the quantity of each item and the page updates the total amount on the fly. The author generates the shopping cart with PHP but doesn't know enough about javascript and DOM Events to be confident about how to walk the tree or use capturing event listeners (or even that they exist), so instead outputs the calculation script in the onforminput="" attribute with PHP since he already has implemented the logic to output the actual shopping cart itself with PHP. The end result might be something like:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/804

> Also, why couldn't scripts use the existing events for the first case?

You need a capturing event listener for that, which is not available as markup and many authors who know enough to use event handler attributes don't know that capturing event listeners exist or how they work.

> And for the latter one there could be just a javascript function to call.

If you have several event handler content attributes you would need to call all of them. It's more convenient to dispatch an event.
Comment 16 Olli Pettay 2011-01-27 09:39:26 UTC
(In reply to comment #15)
> http://software.hixie.ch/utilities/js/live-dom-viewer/saved/804
So that could be written close the way the example 1 or 3 in 
http://www.w3.org/Bugs/Public/attachment.cgi?id=947


> 
> You need a capturing event listener for that, which is not available as markup
> and many authors who know enough to use event handler attributes don't know
> that capturing event listeners exist or how they work.
And why exactly do you need capturing event listeners?


> If you have several event handler content attributes you would need to call all
> of them. It's more convenient to dispatch an event.
So why would it be more convenient to split the code to several
forminput/change event handlers than just have one function?
Comment 17 Simon Pieters 2011-01-27 10:09:49 UTC
(In reply to comment #16)
> (In reply to comment #15)
> > http://software.hixie.ch/utilities/js/live-dom-viewer/saved/804
> So that could be written close the way the example 1 or 3 in 
> http://www.w3.org/Bugs/Public/attachment.cgi?id=947

Ah. I assumed that change and input didn't bubble. That makes my case weaker indeed.

> > You need a capturing event listener for that, which is not available as markup
> > and many authors who know enough to use event handler attributes don't know
> > that capturing event listeners exist or how they work.
> And why exactly do you need capturing event listeners?

Since change and input bubble, I don't. I do need to name="" my <output>s and put the logic further away from the <output>s, but that's not a big deal.

 
> > If you have several event handler content attributes you would need to call all
> > of them. It's more convenient to dispatch an event.
> So why would it be more convenient to split the code to several
> forminput/change event handlers than just have one function?

Each <output> updates its own value when something changes. Just a different coding style.
Comment 18 Mounir Lamouri 2011-01-27 14:39:49 UTC
So, there is still one situation mentioned by Hixie in comment 2 that hasn't been discussed: when form controls are "all over the place". I guess that means:
<form id='f'></form>
<input form='f' name='a'>
<input form='f' name='b'>
<output form='f' onforminput="value=parseFloat(a.value)+parseFloat(b.value);">

In that case we can't indeed use the capture or bubbling phases of the input and change events but I think there is no reason to care too much about this case given that I guess the real use cases to have form controls not descendants of their form owners is when they are very far away in the tree and I would guess that should not happen when you want to have an interaction between form controls.

At worst, it's always possible to do it but it would be more painful:
<form id='f'></form>
<input form='f' name='a' oninput="updateOutput();">
<input form='f' name='b' oninput="updateOutput();">
<output form='f' name='o'>
<script>
  function updateOutput(aForm) {
    aForm.o.value = parseFloat(aForm.a.value) + parseFloat(aForm.b.value);
  }
</script>
Comment 19 Olli Pettay 2011-01-27 14:52:16 UTC
(In reply to comment #18)
 
> In that case we can't indeed use the capture or bubbling phases of the input
> and change events 
?

Just add event listener using addEventListener or oninput / onchange to 
document or root element or somewhere and there just check
if event.target.form is the form you're interested in.
Comment 20 Mounir Lamouri 2011-01-27 15:05:33 UTC
(In reply to comment #19)
> (In reply to comment #18)
> 
> > In that case we can't indeed use the capture or bubbling phases of the input
> > and change events 
> ?
> 
> Just add event listener using addEventListener or oninput / onchange to 
> document or root element or somewhere and there just check
> if event.target.form is the form you're interested in.

I would personally prefer oninput on the form controls but both solutions work.
I didn't want to say that there is no solution. I just wanted to make sure all points from comment 2 have been addressed ;)
Comment 21 Ian 'Hixie' Hickson 2011-03-03 23:21:31 UTC
Hmm, the bubbling nature of these events combined with the change to put the event handlers on every element does make the case for this feature rather weaker. (They were added before we had changed the latter.)

EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with reporter's comments.
Comment 22 contributor 2011-03-03 23:22:28 UTC
Checked in as WHATWG revision r5928.
Check-in comment: Drop forminput and formchange events, and their associated machinery, since you can now put oninput and onchange everywhere which makes them far less compelling.
http://html5.org/tools/web-apps-tracker?from=5927&to=5928
Comment 23 Michael[tm] Smith 2011-08-04 05:06:17 UTC
mass-moved component to LC1