This project is archived and is in readonly mode.

#776 ✓invalid
Jacob

toQueryString does not include <button> values

Reported by Jacob | November 1st, 2009 @ 03:58 AM | in 2.0 (closed)

toQueryString ignores the <button> element.

A really simple proposed fix for Mootools core v1.2.5:

Change Line 1742
FROM: this.getElements('input, select, textarea', true).each(function(el){
TO: this.getElements('input, select, textarea, button', true).each(function(el){

Thanks
Jacob

Comments and changes to this ticket

  • Sebastian Markbåge

    Sebastian Markbåge November 6th, 2009 @ 08:48 PM

    • State changed from “new” to “invalid”

    The purpose of toQueryString is to simulate what happens when a form is submitted. Only one button value is ever sent depending on which button was pressed. This goes for both and . If the form is submitted without pressing a specific button, then no button value is sent. This is what MooTools is simulating, since there's no button context.

    If you want to add the value of a specific button you should find that button explicitly and send it. Or use a hidden field.

    https://mootools.lighthouseapp.com/projects/2706/tickets/776

    http://www.w3.org/TR/html401/interact/forms.html#successful-controls

  • Jacob

    Jacob November 6th, 2009 @ 09:02 PM

    • Assigned user set to “Sebastian Markbåge”

    Im not 100% sure about your response, so I will just show you an example of my issue (perhaps I'm missing something obvious):

    I would like to turn this (simplified example) form into a query string:
    <form><br/> <input type="text"> <button type="submit"> </form><br/>

    whereas right now I can only do this:

    Both are valid, yet only one works. I hope this clarifies the case.
    Thanks for the response,
    Jacob

  • Jacob

    Jacob November 6th, 2009 @ 09:02 PM

    Im not 100% sure about your response, so I will just show you an example of my issue (perhaps I'm missing something obvious):

    I would like to turn this (simplified example) form into a query string:
    <form><br/> <input type="text"> <button type="submit"> </form><br/>

    whereas right now I can only do this:
    <form><br/> <input type="text"> <input type="submit"> </form><br/> Both are valid, yet only one works. I hope this clarifies the case.
    Thanks for the response,
    Jacob

  • Jacob

    Jacob November 6th, 2009 @ 09:03 PM

    Sorry about the duplicate response, I forgot the backticks

  • Sebastian Markbåge

    Sebastian Markbåge November 6th, 2009 @ 09:30 PM

    Actually, as of MooTools 1.2.3 neither would work.

    You should either use a hidden field:

    <form><br/> <input type="text" name="txt" value="foo" /> <input type="hidden" name="btn" value="bar" /> <button type="submit">Send</button> </form><br/>

    Or append the value of the button:

    $('myform').toQueryString() + '&btn=' + encodeURIComponent($('mybutton').get('value'));

    This is because a button value is never added to a querystring unless it's clicked.

  • Jacob

    Jacob November 8th, 2009 @ 03:08 AM

    "Actually, as of MooTools 1.2.3 neither would work."

    Interesting- I'm still using 1.2.1 for production so this is good to know.

    "This is because a button value is never added to a querystring unless it's clicked." I think this is where we're not connecting; the <button> is the only clickable element in my form, and when it is clicked it is not getting added to the query string. Ever. It is the only submit button I can use in my context.

    I hope that clarifies,
    Jacob

Create your profile

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

Shared Ticket Bins

People watching this ticket

Referenced by

Pages