#85 bug
John-David Dalton

Make Form#serializeElements more accurate to the spec.

Reported by John-David Dalton | May 8th, 2008 @ 03:18 PM | in After 1.7

As this page points out: http://www.malsup.com/jquery/for...

Prototype needs to follow the w3c spec a bit more: http://www.w3.org/TR/html401/int...

With recent commits we have ignored the file input elements, that's a start. http://github.com/sstephenson/pr...

We still need to ignore reset buttons and properly handle input type "image". We should also allow the "submit" option to be an element in case multiple buttons have the same name.

Background info: http://github.com/sstephenson/pr...

Comments and changes to this ticket

  • John-David Dalton

    John-David Dalton May 8th, 2008 @ 04:59 PM

    • Assigned user set to “John-David Dalton”
    • State changed from “new” to “bug”

    removed patch because it didn't follow the spec properly

  • Andrew Dupont

    Andrew Dupont May 8th, 2008 @ 05:35 PM

    • Milestone set to 1.7
  • Pradeep Elankumaran

    Pradeep Elankumaran October 7th, 2008 @ 12:54 AM

    • Tag set to form, needs_tests

    serializing'a a text field with a value of "SOP's" does not encode the ' non-alphanumeric character. not sure if this has been fixed in trunk, but thought you guys might like to know.

  • Markus Brüderl

    Markus Brüderl October 8th, 2008 @ 01:10 PM

    • Tag cleared.

    Having more input fields of type submit has one more flaw:

    Passing parameters: $(formname).serialize({submit: buttonClicked})

    where buttonClicked is the clicked Elements' name, the first submit-input field of the form would get postet also

    A good behaviour would be: * none submit-option given - send only first submit input field * submit-option = false - dont send any submit fields * submit-option = name of clicked input field - send only this one input field

    The second option currently doesnt work.

    Fix: In form.js, line 15 if (value != null && (element.type != 'submit' || (!submitted && submit !== false && (!submit || key == submit) && (submitted = true)))) {

    remove the !submit||: if (value != null && (element.type != 'submit' || (!submitted && submit !== false && (key == submit) && (submitted = true)))) {

    That works as described above.

  • James Le Cuirot

    James Le Cuirot December 8th, 2008 @ 02:09 AM

    • Assigned user cleared.

    Is there any particular reason why "image" input tags don't get handled properly yet? Isn't it merely a case of adding element.type != 'image' ?

  • James Le Cuirot

    James Le Cuirot December 8th, 2008 @ 12:41 PM

    It seems that was pretty much all that was required. Here's a patch with tests.

  • James Le Cuirot

    James Le Cuirot December 8th, 2008 @ 11:57 PM

    After trying to use this in my application, I've found that Markus is right. The !submit does cause a problem. However, the submit !== false part of the line is also a bit pointless because key would never be false anyway. The test may pass if both key and submit are undefined but this effectively returns the first submit button found and that is what we want. I think the line should now read...

    {{{ if (value != null && element.type != 'file' && ((element.type != 'submit' && element.type != 'image') || (!submitted && submit && key == submit && (submitted = true)))) { }}}

    This seems to work for me.

  • James Le Cuirot

    James Le Cuirot December 8th, 2008 @ 11:59 PM

    Sorry, I totally get my markup confused these days and there's no damn edit button here.

    if (value != null && element.type != 'file' && ((element.type != 'submit' && element.type != 'image') || (!submitted && submit && key == submit && (submitted = true)))) { }
  • James Le Cuirot

    James Le Cuirot April 6th, 2009 @ 12:19 PM

    I updated Prototype recently and forgot that I'd made this change. Had me scratching my head for a while. Could someone take a look at this?

  • Tobie Langel

    Tobie Langel April 6th, 2009 @ 02:05 PM

    Could you provide a patch against current trunk?

    That would be useful.

  • James Le Cuirot

    James Le Cuirot April 6th, 2009 @ 04:28 PM

    Here you go. I found the conditions still weren't quite right but I've got it now. The tests pass and it still works in my application. I had to change (key == submit) to (submit == undefined || key == submit). Adding this had the same effect as !submit but without the problem that Markus described.

  • Juriy Zaytsev

    Juriy Zaytsev April 6th, 2009 @ 06:35 PM

    • Tag set to patched, tested

    It's a good idea to replace submit == undefined with typeof check (or with Object.isUndefined or with void)

  • James Le Cuirot

    James Le Cuirot April 7th, 2009 @ 12:19 AM

    Good call. I can sometimes still cut myself on the sharp edges of JavaScript!

  • Samuel Lebeau

    Samuel Lebeau August 26th, 2009 @ 08:10 AM

    • Tag changed from patched, tested to patched
    • Assigned user set to “Samuel Lebeau”
  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    • Assigned user cleared.

    [responsible:none bulk edit command]

  • Radoslav Stankov

    Radoslav Stankov March 1st, 2010 @ 08:57 PM

    • Tag changed from patched to needs:review, patched, section:dom
  • Victor

    Victor October 28th, 2010 @ 12:44 PM

    • Importance changed from “” to “”

    And what about select-many element? Current realization not only differs from spec, but also has different results for Form.serialize and Form.Element.serialize:

    <form id="form1" method="get" action="#">
      <select multiple="multiple" id="select1" name="select1">
        <option value="1">1</option>
        <option value="2" selected="selected">2</option>
        <option value="3">3</option>
        <option value="4" selected="selected">4</option>
        <option value="5">5</option>
    <script type="text/javascript">
    $("form1").serialize();   // "select1=2%2C4"
    $("select1").serialize(); // "select1=2&select1=4"

    Attached HTML test page (tested in IE6-7-8, Opera 9.63-10, Firefox 3.0-3.5, Chrome 6).

  • Andrew Dupont

    Andrew Dupont November 2nd, 2010 @ 07:40 AM

    • Milestone changed from 1.7 to After 1.7
    • Assigned user set to “Andrew Dupont”
    • Importance changed from “” to “Medium”

    Pushing this back, but we should take a look at it for 1.7.1.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins