Bug 3481 - form elements added via innerHTML are not accessible via xpath style syntax
Summary: form elements added via innerHTML are not accessible via xpath style syntax
Status: VERIFIED WORKSFORME
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 412
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Darin Adler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-12 14:14 PDT by Stuart Morgan
Modified: 2005-08-19 09:35 PDT (History)
2 users (show)

See Also:


Attachments
Testcase (1.77 KB, text/html)
2005-06-12 14:15 PDT, Stuart Morgan
no flags Details
Possible solution (692 bytes, patch)
2005-06-14 07:01 PDT, Niels Leenheer (HTML5test)
darin: review-
Details | Formatted Diff | Diff
Updated patch (694 bytes, patch)
2005-06-17 00:21 PDT, Niels Leenheer (HTML5test)
darin: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stuart Morgan 2005-06-12 14:14:32 PDT
* SUMMARY
a new element added to a form by setting innerHTML on an existing form element
is not accessible via document.form_name.newElement 

* STEPS TO REPRODUCE
1. see attached

* RESULTS 
newElement should be accessible

* NOTES
Works in Firefox

Apple Bug: rdar://4031024
Comment 1 Stuart Morgan 2005-06-12 14:15:00 PDT
Created attachment 2276 [details]
Testcase
Comment 2 Stuart Morgan 2005-06-12 14:15:50 PDT
3/1/05 6:00 PM Darin Adler:
I think this is because the elements aren't added to the form's elements array.
That's supposed to be done by registerFormElement, which should be called.
Comment 3 Niels Leenheer (HTML5test) 2005-06-14 05:58:49 PDT
The problem originated from the innerHTML implementation. The innerHTML
implementation creates a document fragment (that does not contain the 
containing form). For each node that is created the constructor tries
to find the form, but fails. So registerFormElement() is indeed not
called.

I'll investigate if we can reuse a solution from Konqueror, because 
it is not affected by this bug.
Comment 4 Niels Leenheer (HTML5test) 2005-06-14 07:01:52 PDT
Created attachment 2329 [details]
Possible solution

This patch modifies the insertedIntoDocument() function to handle
inserting of documentfragments that do not have a dormant form.
The patch looks for the correct form and registers the form element.
Comment 5 Joost de Valk (AlthA) 2005-06-15 00:48:12 PDT
Comment on attachment 2329 [details]
Possible solution

works for me.
Comment 6 Darin Adler 2005-06-16 09:54:34 PDT
Comment on attachment 2329 [details]
Possible solution

Patch looks fine, aside from a couple minor stylistic issues:

1) We don't normally mark our local variables const even though I understand
that there is a slight value in doing so to clarify that they can never be
modified.

2) We don't normally put the * next to the type, although I don't know if the
coding style document mentions this.

3) I personally prefer the style where the declaration is inside the if for
code like this.

4) We would normally name this "newForm" rather than "newform", preferring the
"intercap" style to the "smush words together" style.

Anyway, that's all trivia: r=me.
Comment 7 Niels Leenheer (HTML5test) 2005-06-17 00:21:03 PDT
Created attachment 2418 [details]
Updated patch

Fixed some minor stylistic issues
Comment 8 Darin Adler 2005-06-18 17:47:56 PDT
We also need an automated test for this. I'll attempt to turn the test case into a layout test, but in the 
future that should be done before reviewing the patch.
Comment 9 Darin Adler 2005-06-18 18:01:58 PDT
I can't reproduce this problem with Safari 2.0 and WebKit-412 with the test case above.

I'm not going to land the patch that fixes this until I can figure out if there's actually a bug it fixes.
Comment 10 Darin Adler 2005-06-18 18:03:39 PDT
This bug was originally reported in WebKit version 185 -- I believe it has already been fixed.
Comment 11 Darin Adler 2005-06-18 18:13:53 PDT
While the patch looks fine, it fixes a bug that does not exist. The attach function already handles this case 
just fine.
Comment 12 mitz 2005-06-21 06:09:32 PDT
Testcase (In reply to comment #9)
> I can't reproduce this problem with Safari 2.0 and WebKit-412 with the test case above.

Me neither (WebKit-412.6), but I can reproduce it with ToT so this may have been (re-)broken very 
recently. In fact, the layout test fast/forms/element-by-name test fails with ToT.
Comment 13 Darin Adler 2005-08-07 19:25:25 PDT
Hmm, no, I can't reproduce any problem at all now. This seems fixed on TOT, and the layout test works 
too. If you see a problem in the future, please write a new bug report so we can be clear on what 
specifically is going wrong without any confusing history about how it used to fail a different way in the 
past.