Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#13475 closed bug (notabug)

.serialize() button

Reported by: dalemac.09@… 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?

Change History (3)

comment:1 Changed 11 years ago by dalemac.09@…

comment:2 Changed 11 years ago by dmethvin

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.

comment:3 Changed 11 years ago by dalemac.09@…

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.

Note: See TracTickets for help on using tickets.