Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#13651 closed bug (invalid)

$(form).serialize() fails when the form has an element with ID/name equals "elements"

Reported by: john.pacey.anthony@… Owned by: john.pacey.anthony@…
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

$(form).serialize() fails if the HTML form has an input or select control with ID (or possibly with the name attribute) set to "elements". This seems to be because the $.serialize() function looks for all "properties" of form "this" having a key equals to "elements". But the input/select form control having its id="elements" seems to override that form property somehow, thus resulting in the serialization of an empty array of form elements :(

For example, attempting to serialize a form defined as such:

<form id='perioricTableSubmissionForm'>
  <input id="professor" name="professor"/>
  <select id="department" name="department">...</select>
  <select id="elements" name="elements[]" multiple>...</select>
  ...
</form>

Would return a blank string when calling

$('form').serialize();

because the serialize() method in jQuery does something like this:

...
var elements = $.prop(this, "elements");
...

Change History (4)

comment:1 Changed 6 years ago by Rick Waldron

Owner: set to john.pacey.anthony@…
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.

To get you started, use the appropriate boilerplate:

Open the link and click to "Fork" (in the top menu) to begin.

Also, please read: http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/

comment:2 Changed 6 years ago by dmethvin

This sounds like our old friend DOM property aliasing, which we can't fix. http://kangax.github.com/domlint/

comment:3 Changed 6 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

comment:4 Changed 5 years ago by timmywil

#14594 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.