Skip to main content

Bug Tracker

Side navigation

#13475 closed bug (notabug)

Opened February 19, 2013 01:28PM UTC

Closed February 19, 2013 04:57PM UTC

Last modified February 19, 2013 05:15PM UTC

.serialize() button

Reported by: dalemac.09@googlemail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

Serialize() should serialize all successful controls. However, it appears to ignore <input type="submit"> and <button> elements completely.

W3C clearly states that "If a form contains more than one submit button, only the activated submit button is successful."

http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2

The serialize documentation states "No submit button value is serialized since the form was not submitted using a button" however that is a very general and wide sweeping statement! the form could very easily be submitted using a form button, such as in the example below.

consider the following HTML:

<form id="form_1">
<fieldset>

<input type="text" name="input_1">

<input type="submit" name="submit_1" value="submit_1">
<input type="submit" name="submit_2" value="submit_2">

</fieldset>
</form>

with the following jQuery:

$("#form_1").submit( function() {
var data = $(this).serialize();

$.ajax( function() {
...
});
});

If Serialize() completely ignores these elements how are we supposed to now which form action should be performed when the data reaches the server?

Attachments (0)
Change History (3)

Changed February 19, 2013 01:35PM UTC by dalemac.09@googlemail.com comment:1

Changed February 19, 2013 04:57PM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed

There is nothing .serialize() knows that tells it you are inside a submit handler and the user has pushed a specific button. You can add anything you like to the serialized string. You would need to figure out which button was pressed, I don't think it's in the Event object you get. But that's a problem best solved in the forum or StackOverflow since this is not a bug in `.serialize() and it's documented to behave the way it does.

Changed February 19, 2013 05:15PM UTC by dalemac.09@googlemail.com comment:3

The documentation clearly states that 'successful controls' are serialized. The documentation even points the the W3C article that defines what a 'successful control' is. It's right there on the second list item.

Even if this cannot be implemented the documentation needs to be rewritten. The following paragraph is misleading.

''Note: Only "successful controls" are serialized to the string. No submit button value is serialized since the form was not submitted using a button. For a form element's value to be included in the serialized string, the element must have a name attribute. Values from checkboxes and radio buttons (inputs of type "radio" or "checkbox") are included only if they are checked. Data from file select elements is not serialized.''

''No submit button value is serialized since the form was not submitted using a button'' makes absolutely no sense.

Thanks, I know exactly how to work around this issue but thought it might be helpful to open a bug ticket as the documentation clearly contradicts the article it references.