Closed Bug 121726 Opened 23 years ago Closed 23 years ago

The order of the form elements changed when the name property of the form element is setted by using JavaScript.

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
major

Tracking

()

RESOLVED FIXED
mozilla0.9.9

People

(Reporter: bae, Assigned: zhayupeng)

Details

Attachments

(3 files)

Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.7+) Gecko/20020122

When we change the name property of the form element by using JavaScript then 
the order of the form elements is changed too. It mkaes impossible to adderss 
the elements of form by the "some_form.elements[i]" way.

For example if we have JavaScript code like this:
 some_form.elements[0].name = new_name;
 some_form.elements[0].value = new_value;

then actualy we set new_value to some another element of the form instead 
renamed element.

Note that Netsacpe 4.xx does not change order of elements after renaming.

This is not a windows scecific bug, Mozilla have described behavior on Solaris 
platform too.
Browser, not engine. Reassigning to DOM Level 0

bae@sparc.spb.su : note, you can attach a reduced testcase bugs
(use the "Create a New Attachment" link above). Normally we need either
a testcase or a URL to go to; otherwise, we can't debug the problem.

However, I believe this is a duplicate of another bug; will post
that in a minute...
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
This observation was made in bug 105398:

------- Additional Comment #1 From Boris Zbarsky 2001-10-18 07:39 -------

The real bug is that the form.elements array is sorted incorrectly.  In
particular, the sort order _changes_ when you change an element's name.

See also bug 49951.

--------------------------------------------------------------------------


Note that bug 105398 was then duped against bug 49951,
"form.elements[] ordered differently than 4.x"

So, I will dupe this bug, too. If anyone disagrees, please 
reopen this bug; thanks - 

*** This bug has been marked as a duplicate of 49951 ***
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
Andrew: thanks! If you have a chance, though, could you attach your
testcase to bug 49951? That's where the work is going to be done.

You are cc'ed on that bug, so you'll be able to follow its progress. 
ping.liao@sun.com: I noticed you cc'd yourself on this bug. 
But this bug has been marked a duplicate of bug 49951.

So you might want to cc yourself there - that's where all the
work will be done, and where all the updates will come from. 
We should not remove element from element array when name, id or type changed.
I don't think this bug is dup of 49951, 49951 is another proble when parser
form element into vector.
Please verify. thanks!
I don't believe this is dup of 49951 - seems as different problems to me
This patch I supplied seems have some problem...
If the element's name set from none to a not none value, we should remove it 
from the noNameElementTable.
But my patch break this logic by simply remove those code.
Later I will supply another patch to resolve this problem.
Could someone give me some suggestion? Really thanks!

BTW:Reopen this bug.
I think that mNoNameLookupTable is used for form elements which is not supposed
to get into form.elements array, isn't it?
Reopened due to Denis's request.
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
Over to jkeiser; this is his ballpark.
Assignee: jst → jkeiser
Denis:
mNoNameLookupTable is a hastable that store element that out of following 
element type:
  case NS_FORM_BUTTON_BUTTON :
  case NS_FORM_BUTTON_RESET :
  case NS_FORM_BUTTON_SUBMIT :
  case NS_FORM_INPUT_BUTTON :
  case NS_FORM_INPUT_CHECKBOX :
  case NS_FORM_INPUT_FILE :
  case NS_FORM_INPUT_HIDDEN :
  case NS_FORM_INPUT_RESET :
  case NS_FORM_INPUT_PASSWORD :
  case NS_FORM_INPUT_RADIO :
  case NS_FORM_INPUT_SUBMIT :
  case NS_FORM_INPUT_TEXT :
  case NS_FORM_SELECT :
  case NS_FORM_TEXTAREA :
  case NS_FORM_FIELDSET :
mNoNameLookupTable holds form controls that are of types *not* listed above.
Attached patch PatchSplinter Review
Remove AddElement/RemoveElement code when change element's name.
But leave type change code.

jkeiser: Thanks for explaining so much detail tomorrow. But I have one more
problem following:
If javascript change element's type from text to hidden or anything else in the
namedFormControl types. We should not remove it from .elements right? But if we
do the removeElement/addElement the order of form's elements will be changed...

Hope you have idea on this.
Attachment #66392 - Attachment mime type: text/plain → text/html
Changing type from text to hidden, we should not really remove it and re-add it,
but that's going to be a bigger job than fixing name and id.  You really have to
detect the from-type and to-type and see if they both should stay in
form.elements (implying no change is needed).  The reason for this problem is,
when you change type from text to image, it *should* remove from .elements, and
vice versa--it should add into elements when type changes from image to text.

Plans are in the works to make AddElement() work proper-like.  I think we should
avoid changing the type case at the moment.  If you want to work on those plans,
in fact, I can give you gobs of relevant code and point you in the right
direction :)

Let me know what you want to do; the patch you submitted looks good, even works
on Bugzilla, the Ultimate Forms Testing Ground.

Those interested in this bug may also be interested in bug 123302.  Or not.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Target Milestone: --- → mozilla0.9.9
Anyway, the patch can fix this bug right? Leave type change issue(It's not in 
the spec).
So, please review it and make it check in if possible. Thanks.
Comment on attachment 67711 [details] [diff] [review]
Patch

r=jkeiser
Attachment #67711 - Flags: review+
Comment on attachment 67711 [details] [diff] [review]
Patch

sr=jst, but the empty lines above the lines that were removed should be taken
out too.
Attachment #67711 - Flags: superreview+
Thanks Pete for the fix, I just checked it in.

FIXED.
Status: NEW → RESOLVED
Closed: 23 years ago23 years ago
Resolution: --- → FIXED
->myself for tracking
Assignee: jkeiser → pete.zha
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: